Right clicking

6 posts, 2 answers
  1. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 01 Feb 2011 Link to this post

    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
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 01 Feb 2011 Link to this post

    Hi Hassan,

    Do you want this on RadCalendar, or RadDateTimePicker?
    Thanks
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 01 Feb 2011 Link to this post

    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
  5. DoomerDGR8
    DoomerDGR8 avatar
    133 posts
    Member since:
    Aug 2010

    Posted 12 Feb 2011 Link to this post

    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.
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Feb 2011 Link to this post

    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
  7. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 12 Feb 2011 Link to this post

    Actually, this is a bit cleaner
    void radCalendar1_SelectionChanging(object sender, SelectionEventArgs e)
    {
        e.Cancel = (Control.MouseButtons == System.Windows.Forms.MouseButtons.Right);
    }
Back to Top
UI for WinForms is Visual Studio 2017 Ready