如何在winform中的另一个事件中更改属性时阻止事件

时间:2018-03-02 02:23:49

标签: c# winforms

如何在winform中的另一个事件中更改属性时阻止事件? 我正在制作一个自定义按钮。 所以我使自动文本对齐,我写文本对齐方法。

 private void ResetTextAlignment()
 {
     if(textAlignment != SB_TextAlignmentType.None)
     {
         Size curTextSize = TextRenderer.MeasureText(text, TextFont);

         if (curTextSize.Height > Size.Height)
             textPos.Y = 0;
         else
             textPos.Y = (Size.Height - curTextSize.Height) / 2.0f;

         switch (textAlignment)
         {
             case TextAlignmentType.Left:
                 textPos.X = 0;
                 break;
             case TextAlignmentType.Right:
                 textPos.X = Size.Width - curTextSize.Width;
                 break;
             case TextAlignmentType.Center:
                 if (curTextSize.Width > Size.Width)
                     textPos.X = 0;
                 else
                     textPos.X = (Size.Width - curTextSize.Width) / 2.0f;
                 break;
         }               
     }
     DesignRefresh();
 }

此方法将重置文本位置,但我想调用此方法 控件的大小已更改,字体已更改...等事件回调方法。但是这个方法改变了属性,所以这个方法调用另一个事件方法。

因此,当我在此方法中更改属性时,我必须阻止事件。 我该怎么办?

0 个答案:

没有答案
相关问题