We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Custom Control & First Mouse Click

Thread ID:

Created:

Updated:

Platform:

Replies:

34829 Sep 16,2005 02:19 PM UTC Sep 22,2005 01:34 PM UTC Windows Forms 10
loading
Tags: GridControl
Clinton Nielsen
Asked On September 16, 2005 02:19 PM UTC

Hi, I''m having trouble with putting a custom control in a cell. For some reason, when I click on a button within the custom control cell, it only activates the cell - then I have to click again on the button to actually have the button do something. Any idea how to make the Save and Cancel buttons in this little application respond to the first mouse click? Thanks. ControlClick_6667.zip

Administrator [Syncfusion]
Replied On September 18, 2005 07:06 AM UTC

Hi Tinclon, Please refer the following thread that discusses this issue: http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=27673 Best regards, Jay N

Clinton Nielsen
Replied On September 19, 2005 01:51 PM UTC

I have already read that thread thoroughly, and it is not helping me at all... "The FakeLeftMouseClick is sort of a hack to begin with. It does not always work." In the case in my application - it is not working. Please advise how to correct the problem in a way that actually works. Thanks again.

Administrator [Syncfusion]
Replied On September 20, 2005 07:32 AM UTC

Hi Tinclon, Can you please try this modified sample to see if it would serve your needs? ControlClick.zip Best regards, Jay N

Clinton Nielsen
Replied On September 20, 2005 02:37 PM UTC

Thank you for your quick response. Your solution works - I think however, my example program was too simple. You are using the two lines: ActiveXSnapshot.FakeLeftMouseClick(focusControl.ButtonSave, p) focusControl.ButtonSave.PerformClick(); The first line (FakeLeftMouseClick) still does nothing and does not affect your code at all if removed. As for the second line, it works wonderfully for buttons - because the PerformClick() method is available. I however, am going to be placing TabControlAdvs and GridControls, and Labels, and CheckBoxes, and all sorts of other stuff in the focusControl: very few of which have the PerformClick() method. As such, my problem still remains - I have no way of getting the click event to the components of my focusControl. Basically, I need to be able to forward the click to any type of control contained within the focusControl. Thx.

Administrator [Syncfusion]
Replied On September 21, 2005 10:09 AM UTC

Hi Tinclon, I could see the issue and have forwarded it the development team for their thoughts. Grid just sends the MouseButtonUp and MouseButtonDown messages at client coordinates. /// /// Sends a WM_LBUTTONDOWN and WM_LBUTTONUP message to the control at the specified client coordinates. /// /// The target control. /// The client coordinates where to simulate the click. public static void FakeLeftMouseClick(Control c, Point point) { IntPtr lParam = NativeMethods.Util.MAKELPARAM(point.X, point.Y); IntPtr wParam = (IntPtr) NativeMethods.MK_LBUTTON; //(int) e.Button; NativeMethods.PostMessage(c.Handle, NativeMethods.WM_LBUTTONDOWN, wParam, lParam); NativeMethods.PostMessage(c.Handle, NativeMethods.WM_LBUTTONUP, wParam, lParam); } You could try setting the focus to the usercontrol on mousemove event to see if that would serve your needs. private void gridControl1_MouseMove(object sender, MouseEventArgs e) { int row, col; this.gridControl1.PointToRowCol(new Point(e.X, e.Y), out row, out col); if(row == 1 || row == 3) { if(this.gridControl1.Model[row, col].CellType == "Control") { this.gridControl1.CurrentCell.MoveTo(row, col); this.gridControl1.CurrentCell.BeginEdit(); } } } Best regards, Jay N

Clinton Nielsen
Replied On September 21, 2005 02:44 PM UTC

I actually tried something like that in the CellHitTest event and it worked. The problem there is that I need the focus to remain wherever it is until the user actually clicks. If the focus were to move every time the user moved their mouse over the control it would just be too confusing. I was wondering if perhaps you could post what NativeMethods.PostMessage(...) does. Perhaps then I could just create my own "FakeLeftMouseClick" method that actually sends a click message. Thanks again.

Administrator [Syncfusion]
Replied On September 21, 2005 07:19 PM UTC

Hi Tinclon, I played around a bit with your sample and I think using the GetChildAtPoint method will fix your problem. Try using this code: private void gridControl1_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e) { if(e.RowIndex == 1 || e.RowIndex == 3) { if (this.gridControl1.CurrentCell.HasCurrentCellAt(e.RowIndex, e.ColIndex)) { GridCellLayout layout = this.gridControl1.GetCellRenderer(e.RowIndex, e.ColIndex).GetCellLayout(e.RowIndex, e.ColIndex, this.gridControl1.Model[e.RowIndex, e.ColIndex]); bool clickOnCell = layout.ClientRectangle.Contains(new Point(e.MouseEventArgs.X, e.MouseEventArgs.Y)); Control focusControl = this.gridControl1[e.RowIndex, e.ColIndex].Control; bool beginEdit = focusControl != null; if (beginEdit) { this.gridControl1.CurrentCell.BeginEdit(); if (this.gridControl1.CurrentCell.HasControlFocus && e.MouseEventArgs.Button == MouseButtons.Left) { this.gridControl1.Update(); Point loc = layout.ClientRectangle.Location; Point targetPoint = new Point(e.MouseEventArgs.X-loc.X, e.MouseEventArgs.Y-loc.Y); Control targetControl = focusControl.GetChildAtPoint(targetPoint); if (targetControl == null) targetControl = focusControl; else { Point childLocation = targetControl.Location; targetPoint = new Point(targetPoint.X-childLocation.X, targetPoint.Y-childLocation.Y); } ActiveXSnapshot.FakeLeftMouseClick(targetControl, targetPoint); } } } } } Stefan

Clinton Nielsen
Replied On September 22, 2005 12:27 AM UTC

I see where you''re going with the GetChildAtPoint method - but I implemented it directly into the sample and it didn''t work. Did it work for you? Did you change anything else. If it did work, could you perhaps upload the new version? Thanks.

Administrator [Syncfusion]
Replied On September 22, 2005 01:23 AM UTC

Hi, you can download it here: ControlClick.zip It works for me but let me know if you see problems with it. Stefan

Clinton Nielsen
Replied On September 22, 2005 01:34 PM UTC

Thank you. Yes, I see the difference. In the code I was using, the buttons inside my custom control were .TabStop = true, whereas in yours they were .TabStop = false. So basically, as long as all my interior controls are not set to TabStop, then everything works perfectly. The only problem is that I still need the user to be able to tab once within the custom control. Perhaps I''ll just have to handle the KeyDown event myself and hardcode all the tabbing functionality. ~Tinclon

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;