2

디자이너 내에서 실행되지 않는 코드 줄을 실행하여 내 컨트롤의 모든 공용 속성이 더 이상 디자이너에 나타나지 않습니다. 이 때문에 Visual Studio 디자인 뷰에서 해당 컨트롤을 사용하는 내 양식을 더 이상 볼 수 없습니다.디자이너에서 블록 코드 실행

해당 코드 줄은 이미지 처리를 수행하는 안전하지 않은 코드 프로젝트를 호출합니다. 그것을 주석 처리하면 디자인보기가 다시 생생 해집니다. 그러나 코드가 완벽하게 실행되므로 디자이너에서 코드가 실패하는 이유를 알 수 없습니다. 이 호출되는 코드입니다 :

 /// <summary> 
     /// Performs a color adjustment on the source bitmap. 
     /// </summary> 
     /// <param name="source">The bitmap to be processed. This is changed by the 
     /// process action.</param> 
     /// <param name="redChange">change to the red value. Can be negative.</param> 
     /// <param name="greenChange">change to the green value. Can be negative.</param> 
     /// <param name="blueChange">change to the blue value. Can be negative.</param> 
     /// <returns></returns> 
     public static Bitmap ProcessColor(Bitmap source, int redChange, int greenChange, int blueChange) 
     { 
      sourceBitmap = source; 

      // lock the source bitmap 
      sourceBitmapData = getBitmapData(sourceBitmap, ref sourceWidth); 
      sourcepBase = (Byte*)sourceBitmapData.Scan0.ToPointer(); 

      PixelData* pPixel; 

      for (int y = 0; y < source.Height; y++) 
      { 
       pPixel = (PixelData*)(sourcepBase + y * sourceWidth); 
       for (int x = 0; x < source.Width; x++) 
       { 
        int redVal = pPixel->red + redChange; 
        if (redVal <0) redVal = 0; 
        if (redVal > 255) redVal = 255; 
        pPixel->red = (byte)redVal; 

        int greenVal = pPixel->green + greenChange; 
        if (greenVal <0) greenVal = 0; 
        if (greenVal > 255) greenVal = 255; 
        pPixel->green = (byte)greenVal; 

        int blueVal = pPixel->blue + blueChange; 
        if (blueVal < 0) blueVal = 0; 
        if (blueVal > 255) blueVal = 255; 
        pPixel->blue = (byte)blueVal; 

        pPixel++; 
       } 
      } 

      sourceBitmap.UnlockBits(sourceBitmapData); 
      sourceBitmapData = null; 
      sourcepBase = null; 

      return source; 
     } 

합니다 (OpenNETCF 커뮤니티의 의례)

내 프로젝트가 안전하지 않은 것으로 표시되지 않지만, 위의 코드에있는 프로젝트는 안전하지 않은 것으로 표시됩니다. 두 프로젝트 모두 안전하지 않다고 표시해야합니까?

또는 디자이너에서 해당 코드 줄을 차단할 수있는 방법이 있습니까 (제공된 코드에서 이미지의 사용되지 않는 버전을 생성하기 때문에 디자인보기에서 실제로이 코드의 출력이 필요하지는 않습니다. 영상).

편집 : 코드 실행을 차단해도 문제가 해결되지 않습니다. 라인을 주석 처리 만하면 디자인 뷰가 작동합니다. 라인을 넣으면 (if [false == true] 문을 넣어도) 디자이너가 양식 대신 오류를 표시합니다.

답변

5

if 코드의 일부 :

if(Site != null && !Site.DesignMode) 
{ 
    // Your "unsafe" code goes here 
} 

짐승 DesignMode이 실제로 무엇인지에 모드 정보에 this post를 참조하십시오 : 당신은 컴팩트 프레임 워크를 사용하는 경우

if(!DesignMode) 
{ 
    // Your "unsafe" code goes here 
} 

, 이것을 사용 .

+1

까지 내가 볼 수있는대로 CF에는 '대해 designMode가'없습니다. 아니면 다른 참조에 있습니까? – GenericTypeTea

+0

네, 고마워요. 그것을 놓쳤습니다. 내 대답을 편집했습니다. –

+0

내가 발견 경우 (this.Site.DesignMode!) { // 등 } 하지만 그건 당신이 사용하는 경우 대해 designMode 속성이 올바른 값을 반환하지 않습니다 – GenericTypeTea

3

나는 이것을 만들지 않았지만 유용한 트릭을 추가 할 것이라고 생각했다. -->here<--.

그냥 컨트롤에 추가하고 적절하게 사용하십시오.

public static bool IsDesignMode 
{ 
    get 
    { 
    return AppDomain.CurrentDomain.FriendlyName.Contains("DefaultDomain"); 
    } 
} 

또는 우리 VB.NET의 사람들에 대한

:

Public Shared ReadOnly Property IsDesignMode() As Boolean 
    Get 
     Return AppDomain.CurrentDomain.FriendlyName.Contains("DefaultDomain") 
    End Get 
    End Property 
+1

이 메서드의 장점은 컨트롤의 생성자에서도 작동한다는 것입니다. – xsl