Designing Windows.Form with Multiple Panels & # 8594; How to hide one panel (for example, PS layer)

How to hide one panel in Visual Studio 2008 Form Designer as a layer in PS? Otherwise, can anyone recommend another best method for developing several β€œscreens” that the user should click on?

+4
source share
3 answers

What you are describing is a master, and you can explore the approach from Eric J.

However, when I have cases where I want to have several panels in the same space in my user interface, and I want to switch between them in the designer, I like to use TabControl and hide the TabControl tabs. This simplifies user interface management at design time, and the code is pretty simple to switch between tabs at run time.

I made my own control that comes from TabControl called HiddenTabsControl, which is very simple. The class only overrides WndProc and allows the TabControl base class to handle everything else. All you have to do is:

  • Add a new item to your project.
  • Select Custom Control,
  • Name it something like HiddenTabsControl.
  • Change the base class to TabControl, remove the constructor and OverPaint override added in Visual Studio.
  • Copy this override for WndProc to the class:

    protected override void WndProc(ref Message m) { // Hide tabs by trapping the TCM_ADJUSTRECT message if (m.Msg == 0x1328 && !DesignMode) { m.Result = (IntPtr)1; } else { base.WndProc(ref m); } } 

Now you can easily change tabs in the designer and design the user interface, and in the code you can handle events for changing tabs as needed. Changing the Selected bookmark is easy with

 this.hiddenTabsControl.SelectedTab = this.tabPageYouWantVisible; 

One of the side effects of removing tabs is the space that the tabs occupy when building the control. Removing them will cause the HiddenTabsControl space to change, reducing it. I usually set the anchor from the HiddenTabsControl from the bottom so that it does not contract.

+17
source

I used this wizard in a recent project and it worked well.

It gives you a basic experience.

+2
source

Another less elegant but quick hack approach is to simply not add a panel to the parent form until runtime. At the same time, the designer has no idea where the panel belongs before compilation, and it will not be displayed.

For example, find the block of code in which you add controls to the parent form:

  //this->Controls->Add(this->panel_X); this->Controls->Add(this->tabControl); this->Controls->Add(this->menuStrip_topMenu); 

Comment or delete an instruction, then find the handle to the event that occurs when the form loads:

  this->Load += gcnew System::EventHandler(this, &MainForm::MainForm_Load); 

Then, in the event handler definition, add the control to the form:

 System::Void MainForm_Load(System::Object^ sender, System::EventArgs^ e) { ... ... this->Controls->Add(this->panel_X); } 

I did not experience any unwanted side effects while doing this, but if someone has a good reason, I would not want to hear it.

+2
source

All Articles