Windows :: Forms :: Control错误地绘制在(0,0)

时间:2011-04-22 16:15:02

标签: .net winforms visual-studio-2010 c++-cli

忽略控件的容器位置,并在窗体上的(0,0)处绘制控件。

容器是位置设置为(26,26)

的面板

据我所知,唯一的区别是当控件的包含面板不可见并且随后变为可见时会发生这种情况。

如果我在面板可见时执行相同的代码,它可以正常工作。

我发现两种情况之间的追踪没有区别。

有没有人对如何避免这种'功能'有任何想法?

Resize :: Layout只是一个根据类型调用相关函数的包装器:

void Resize::Layout(System::Windows::Forms::Control^ Ctrl)
{
  SMSG(String::Format("Resize::Layout {0} ({1}) {2}{3}",
    Ctrl->Name, Ctrl->GetType()->ToString(), Ctrl->Location.ToString(),
    Ctrl->ClientRectangle.Size.ToString()),true);
  // resize the Resize... controls
  if (Ctrl->GetType()->ToString() == "Custom.ResizeLabel")
  {
    safe_cast<Custom::ResizeLabel^>(Ctrl)->Layout();
  }
  else if (Ctrl->GetType()->ToString() == "Custom.ResizePanel")
  {
    safe_cast<Custom::ResizePanel^>(Ctrl)->Layout(Ctrl, true);
  }
  else if(Ctrl->GetType()->ToString() == "Custom.ResizeTabControl")
  {
    safe_cast<Custom::ResizeTabControl^>(Ctrl)->Layout(Ctrl, true);
  }
  else LayoutCtrl(Ctrl);
  SMSG(String::Format("Resize::Layout {0} ({1}) {2}{3}", Ctrl->Name,
    Ctrl->GetType()->ToString(), Ctrl->Location.ToString(),
    Ctrl->ClientRectangle.Size.ToString()),false);
}

这是我对失败案例的追踪:Location和ClientSize是跟踪的值。 OnPaint事件中的ClipRectangle是不同的。

UnderneathButton和OnTopButton包含在HomeButtonsPanel中。

HomeButtonsPanel包含在HomePanel中。

HomePanel包含在HomePanelBorder中。

HomePanelBorder包含在HomeTab中。

HomeTab包含在FormTabs中。

FormTabs包含在FormTabsPanel中。

FormTabsPanel包含在FormPanel中。

FormPanel包含在Form1中。

Resize::Layout HomeButtonsPanel (System.Windows.Forms.Panel) {X=66,Y=68}{Width=75,Height=52}
Resize::Layout UnderneathButton (System.Windows.Forms.Button) {X=0,Y=29}{Width=75,Height=23}
Resize::Layout UnderneathButton (System.Windows.Forms.Button) {X=0,Y=29}{Width=75,Height=23}
Resize::Layout OnTopButton (System.Windows.Forms.Button) {X=0,Y=3}{Width=75,Height=23}
Resize::Layout OnTopButton (System.Windows.Forms.Button) {X=0,Y=3}{Width=75,Height=23}
Resize::Layout HomeButtonsPanel (System.Windows.Forms.Panel) {X=66,Y=68}{Width=75,Height=52}
HomePanel::Layout Height set - {X=0,Y=0}{Width=253,Height=125}
Resize::Layout HomePanel (Custom.ResizePanel) {X=0,Y=0}{Width=253,Height=125}
HomePanelBorder::Layout Height set - {X=0,Y=0}{Width=253,Height=125}
Resize::Layout HomePanelBorder (Custom.ResizePanel) {X=0,Y=0}{Width=253,Height=125}
Resize::Layout HomeTab (System.Windows.Forms.TabPage) {X=4,Y=25}{Width=255,Height=127}
FormTabs::Layout Height set - {X=0,Y=0}{Width=263,Height=156}
Resize::Layout FormTabs (Custom.ResizeTabControl) {X=0,Y=0}{Width=263,Height=156}
FormTabsPanel::Layout Height set - {X=26,Y=26}{Width=263,Height=156}
Resize::Layout FormTabsPanel (Custom.ResizePanel) {X=26,Y=26}{Width=263,Height=156}
FormPanel::Layout Height set - {X=0,Y=0}{Width=315,Height=182}
*** FormPanel - OnSizeChanged:{X=0,Y=0}{Width=315,Height=182}
Resize::Layout FormPanel (Custom.ResizePanel) {X=0,Y=0}{Width=315,Height=182}
Resize::Layout Form1 (EasyButtons.Form1) {X=24,Y=0}{Width=315, Height=208}
*** FormPanel - OnPaint:{X=0,Y=0}{Width=315,Height=182} Clip - {X=26,Y=0,Width=289,Height=182}

这是我对成功案例的追踪!

Resize::Layout HomeButtonsPanel (System.Windows.Forms.Panel) {X=66,Y=68}{Width=75,Height=52}
Resize::Layout UnderneathButton (System.Windows.Forms.Button) {X=0,Y=29}{Width=75,Height=23}
Resize::Layout UnderneathButton (System.Windows.Forms.Button) {X=0,Y=29}{Width=75,Height=23}
Resize::Layout OnTopButton (System.Windows.Forms.Button) {X=0,Y=3}{Width=75,Height=23}
Resize::Layout OnTopButton (System.Windows.Forms.Button) {X=0,Y=3}{Width=75,Height=23}
Resize::Layout HomeButtonsPanel (System.Windows.Forms.Panel) {X=66,Y=68}{Width=75,Height=52}
HomePanel::Layout Height set - {X=0,Y=0}{Width=253, Height=125}
Resize::Layout HomePanel (Custom.ResizePanel) {X=0,Y=0}{Width=253,Height=125}
HomePanelBorder::Layout Height set - {X=0,Y=0}{Width=253,Height=125}
Resize::Layout HomePanelBorder (Custom.ResizePanel) {X=0,Y=0}{Width=253,Height=125}
Resize::Layout HomeTab (System.Windows.Forms.TabPage) {X=4,Y=25}{Width=255,Height=127}
FormTabs::Layout Height set - {X=0,Y=0}{Width=263,Height=156}
Resize::Layout FormTabs (Custom.ResizeTabControl) {X=0,Y=0}{Width=263,Height=156}
FormTabsPanel::Layout Height set - {X=26,Y=26}{Width=263,Height=156}
Resize::Layout FormTabsPanel (Custom.ResizePanel) {X=26,Y=26}{Width=263,Height=156}
FormPanel::Layout Height set - {X=0,Y=0}{Width=315,Height=182}
*** FormPanel - OnSizeChanged:{X=0,Y=0}{Width=315,Height=182}
Resize::Layout FormPanel (Custom.ResizePanel) {X=0,Y=0}{Width=315,Height=182}
Resize::Layout Form1 (EasyButtons.Form1) {X=24,Y=0}{Width=315,Height=208}
*** FormPanel - OnPaint:{X=0,Y=0}{Width=315, Height=182} Clip - {X=0,Y=26,Width=315,Height=156}

0 个答案:

没有答案