This is a migrated thread and some comments may be shown as answers.

Right clicking

5 Answers 98 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
DoomerDGR8 asked on 01 Feb 2011, 03:49 PM
Hi. I need to get me a context menu on the Calendar through which I plan to process the selected date(s) or use the date(s) in other process. I cant understand how'd I go about using a RadContextMenu

5 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 01 Feb 2011, 03:54 PM
Hi Hassan,

Do you want this on RadCalendar, or RadDateTimePicker?
Thanks
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 01 Feb 2011, 04:26 PM
Hi Hassan,

To add a Right Click Context menu to the RadCalendar

private RadContextMenu m_ContextMenu = new RadContextMenu();

form load..
RadMenuItem menuItem = new RadMenuItem("Click Me");
menuItem.Click += new EventHandler(menuItem_Click);
m_ContextMenu.Items.Add(menuItem);
this.radCalendar1.MouseDown += new MouseEventHandler(radCalendar1_MouseDown);

void radCalendar1_MouseDown(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        Point p = (sender as Control).PointToScreen(e.Location);
        m_ContextMenu.Show(p.X, p.Y);
    }
}

void menuItem_Click(object sender, EventArgs e)
{
    MessageBox.Show(this.radCalendar1.SelectedDate.ToLongDateString());
}

Hope that helps
Richard
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 12 Feb 2011, 01:47 PM
Excellent. However, there is an issue that right-clicking also selects/de-selects a date. I need to prevent date selection through right click. I just need it to show a context menu.
0
Richard Slade
Top achievements
Rank 2
answered on 12 Feb 2011, 02:04 PM
Hi Hassan,

To get around it selecting a date on right mouse click, add the following

1: In form load
this.radCalendar1.SelectionChanging += new SelectionEventHandler(radCalendar1_SelectionChanging);

2: Stop selection changed on right click
void radCalendar1_SelectionChanging(object sender, SelectionEventArgs e)
{
    e.Cancel = string.Equals(Control.MouseButtons.ToString(), "Right");
}

Hope that helps
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 12 Feb 2011, 02:06 PM
Actually, this is a bit cleaner
void radCalendar1_SelectionChanging(object sender, SelectionEventArgs e)
{
    e.Cancel = (Control.MouseButtons == System.Windows.Forms.MouseButtons.Right);
}
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Richard Slade
Top achievements
Rank 2
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or