Click here to Skip to main content
15,885,278 members
Home / Discussions / C#
   

C#

 
GeneralUser friendly error Pin
Anonymous21-Jan-04 4:47
Anonymous21-Jan-04 4:47 
GeneralRe: User friendly error Pin
Alex Korchemniy21-Jan-04 4:54
Alex Korchemniy21-Jan-04 4:54 
GeneralRe: User friendly error Pin
Mazdak21-Jan-04 5:04
Mazdak21-Jan-04 5:04 
GeneralRe: User friendly error Pin
eggie521-Jan-04 12:26
eggie521-Jan-04 12:26 
GeneralCustom Panel Pin
ernst wolthaus21-Jan-04 4:24
ernst wolthaus21-Jan-04 4:24 
GeneralRe: Custom Panel Pin
Mazdak21-Jan-04 4:46
Mazdak21-Jan-04 4:46 
GeneralRe: Custom Panel Pin
ernst wolthaus21-Jan-04 7:46
ernst wolthaus21-Jan-04 7:46 
GeneralRe: Custom Panel Pin
Heath Stewart21-Jan-04 5:34
protectorHeath Stewart21-Jan-04 5:34 
If you can't use the designer, just code the controls manually.

As far as displaying custom panels (or any scrollable control, for that matter), derive your custom panel Types (classes) and store the Type of the derivative panels as properties of the item on which the action occurs, such as clicking on a menu item. Since you're dealing with MenuItems, also extend MenuItem with your own class and add a property, kind of like:
public class MyMenuItem : MenuItem
{
  private Type panelType;
  public MyMenuItem() : this(null, null) {}
  public MyMenuItem(string text) : this(text, null) {}
  public MyMenuItem(string text, Type panelType) : base(text)
  {
    this.panelType = panelType;
  }
  public Type PanelType
  {
    get { return this.panelType; }
    set { this.panelType = value; }
  }
}
Treat this menus like normal, adding them to a MenuItems collection just like normal. When a user clicks on the MenuItem, you will use that Type as you'll see shortly. For brevity, assume that each MenuItem uses the same Click event handler:
private void menu_Click(object sender, EventArgs e)
{
  MyMenuItem menu = sender as MyMenuItem;
  if (menu != null)
  {
    if (menu.PanelType != null)
    {
      // If you derived from Panel, cast to the base class here
      // (or even simply Control).
      Panel p = Activator.CreateInstance(menu.PanelType) as Panel;
      if (p != null)
      {
        p.Dock = DockStyle.Fill;
        leftContainer.Controls.RemoveAt(0);
        leftContainer.Controls.Add(p);
      }
    }
  }
}
This is just a very basic example but I hope you get the idea. Creating instances of unknown Types (or from a collection of Types, perhaps configured in a .config file) is fairly common. I do this A LOT in our enterprise app I designed. It goes much deeper than this, but this is the essential idea.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralRe: Custom Panel Pin
Jose Fco Bonnin21-Jan-04 5:52
Jose Fco Bonnin21-Jan-04 5:52 
GeneralRe: Custom Panel THANKS! Pin
ernst wolthaus21-Jan-04 7:42
ernst wolthaus21-Jan-04 7:42 
GeneralChange listbox item index Pin
hazzem elrefai20-Jan-04 21:11
hazzem elrefai20-Jan-04 21:11 
GeneralRe: Change listbox item index Pin
hazzem elrefai20-Jan-04 21:35
hazzem elrefai20-Jan-04 21:35 
Questionhow to make fullscreen game animation ? Pin
tonaxxl20-Jan-04 20:57
tonaxxl20-Jan-04 20:57 
AnswerRe: how to make fullscreen game animation ? Pin
Mazdak20-Jan-04 22:05
Mazdak20-Jan-04 22:05 
AnswerRe: how to make fullscreen game animation ? Pin
Hauptman(n)21-Jan-04 3:43
Hauptman(n)21-Jan-04 3:43 
QuestionStart Calculator and active it again? Pin
god4k20-Jan-04 18:57
god4k20-Jan-04 18:57 
AnswerRe: Start Calculator and active it again? Pin
Kannan Kalyanaraman20-Jan-04 20:05
Kannan Kalyanaraman20-Jan-04 20:05 
GeneralToolbar button images disappear at runtime Pin
Jason Liu20-Jan-04 13:34
Jason Liu20-Jan-04 13:34 
GeneralRe: Toolbar button images disappear at runtime Pin
Anders Molin20-Jan-04 15:20
professionalAnders Molin20-Jan-04 15:20 
GeneralRe: Toolbar button images disappear at runtime Pin
Jason Liu20-Jan-04 15:51
Jason Liu20-Jan-04 15:51 
GeneralRe: Toolbar button images disappear at runtime Pin
Anders Molin20-Jan-04 15:54
professionalAnders Molin20-Jan-04 15:54 
GeneralRe: Toolbar button images disappear at runtime Pin
Jason Liu20-Jan-04 21:55
Jason Liu20-Jan-04 21:55 
QuestionHow to insert a tab into the label text? Pin
Jason Liu20-Jan-04 13:30
Jason Liu20-Jan-04 13:30 
AnswerRe: How to insert a tab into the label text? Pin
Heath Stewart21-Jan-04 4:45
protectorHeath Stewart21-Jan-04 4:45 
GeneralWeird Prob with input keys and toolbar Pin
cgcrute20-Jan-04 12:26
cgcrute20-Jan-04 12:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.