Click here to Skip to main content
15,922,015 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a windows app. There is a menubar on main interface and on the main interface there is a panel. On click event of "View Calender" there is a onother form on the panel. On that form there is a monthcalender. I want to show current date bolded on click event of "Jump to Today" menu item. Please help me. Thanx in advance.

This code is on click event of "View Calender" button, which load the form on panel of main interface.

C#
Calender obj = new Calender();
obj.TopLevel = false;

  if (panel2.Controls.Count > 0)
      {
          panel2.Controls.Clear();
          panel2.Controls.Add(obj);
          obj.TopLevel = false;
          obj.Show();
      }
 else
      {
           obj.TopLevel = false;
           panel2.Controls.Add(obj);
           obj.Show();
      }
Posted
Updated 24-May-12 0:55am
v2

1 solution

Are these forms within an MDI container?

Either way you need to make the reference to the Calendar object (note the spelling :)) available within the context that it needs to be referenced. In this case that means the top level form, i.e.

class MyForm {
 ...

 Calendar calendar = new Calendar();

 void viewCalendar_click(object sender, EventArgs e){
   panel2.Controls.Clear();
   panel2.Controls.Add(obj);
   calendar.TopLevel = false;
   calendar.Show();
 }
}


Then you can refer to it in the event handler of 'Jump to Today':
void jumpToToday_click(object sender, EventArgs e){
  calendar.HighlightDate(DateTime.Today);
}


... obviously you need to write HighlightDate as well and that depends on how your Calendar works, but that should be pretty easy.
 
Share this answer
 
Comments
Wendelius 24-May-12 16:44pm    
OP's comment:
I tried following code. But did not worked.

Collapse | Copy Code
private void viewCalenderToolStripMenuItem_Click(object sender, EventArgs e)
{
Calender obj = new Calender();
obj.TopLevel = false;

if (panel2.Controls.Count > 0)
{
panel2.Controls.Clear();
panel2.Controls.Add(obj);
obj.TopLevel = false;
obj.Show();
}
else
{
obj.TopLevel = false;
panel2.Controls.Add(obj);
obj.Show();
}
}

private void jumpToTodayToolStripMenuItem_Click(object sender, EventArgs e)
{
Calender obj = new Calender();
obj.monthCalendar1.SetDate(DateTime.Now);
}
BobJanova 24-May-12 17:28pm    
That's because you didn't do what I suggested, you're still declaring Calenders (sic) inside each method.
Rajan225 28-May-12 7:45am    
'Calender' is name of other form on which there is 'monthCalender1'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900