开发者

Windows::Forms::Control painted at (0,0) incorrectly

开发者 https://www.devze.com 2023-02-27 20:25 出处:网络
The control\'s container\'s location is ignored and the control is painted at (0,0) on the Form. The container is a panel with Location set to (26,26)

The control's container's location is ignored and the control is painted at (0,0) on the Form.

The container is a panel with Location set to (26,26)

As far as I can tell the only difference is that it happens when the control's containing panel was not Visible and is then made Visible.

If I execute the same code when the panel is Visible it works correctly.

I can see no difference in my tracing between the two cases.

Does anyone have any ideas as to how I can avoid this 'feature'?

Resize::Layout is just a wrapper to call the relevant function dependant on type:

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);
}

Here's my tracing for the failing case: The Location and ClientSize are the values traced. The ClipRectangle in the OnPaint event is different.

The UnderneathButton and OnTopButton are contained in HomeButtonsPanel.

HomeButtonsPanel is contained in HomePanel.

HomePanel is contained in HomePanelBorder.

HomePanelBorder is contained in HomeTab.

HomeTab is contained in FormTabs.

FormTabs is contained in FormTabsPanel.

FormTabsPanel is contained in FormPanel.

FormPanel is contained in 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.ResizePan开发者_运维技巧el) {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}

Here's my tracing for the successful case!

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号