ControlDesigner issue
-
Not sure if this is the correct group for this question but I am working with C#. I'm migrating from VS2005 to VS2022 and having problem with ControlDesigner in my Control. It seems that the ControlDesigner is not functioning. I'm not too familiar with ControlDesigner programming so after working on this for a while I decided to start from scratch. I found an example in Microsoft Help Viewer for ControlDesigner. I copied and pasted the example code into a project UserControl1 and it too does not seem to function. When moving the mouse over the control the outline does not highlight and also the OutlineColor property is not shown in the Properties window. Can someone help? Below is the sample code from Help Viewer. The only difference the test control is called UserControl1 Thank you.
using System.ComponentModel;
namespace TestApp
{
// ExampleControlDesigner is an example control designer that
// demonstrates basic functions of a ControlDesigner.
public class ExampleControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
// This Boolean state reflects whether the mouse is over the control.
private bool mouseover = false;
// This color is a private field for the OutlineColor property.
private Color lineColor = Color.White;// This color is used to outline the control when the mouse is // over the control. public Color OutlineColor { get { return lineColor; } set { lineColor = value; } } public ExampleControlDesigner() { } // Sets a value and refreshes the control's display when the // mouse position enters the area of the control. protected override void OnMouseEnter() { this.mouseover = true; this.Control.Refresh(); } // Sets a value and refreshes the control's display when the // mouse position enters the area of the control. protected override void OnMouseLeave() { this.mouseover = false; this.Control.Refresh(); } // Draws an outline around the control when the mouse is // over the control. protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe) { if (this.mouseover) { pe.Grap
-
Not sure if this is the correct group for this question but I am working with C#. I'm migrating from VS2005 to VS2022 and having problem with ControlDesigner in my Control. It seems that the ControlDesigner is not functioning. I'm not too familiar with ControlDesigner programming so after working on this for a while I decided to start from scratch. I found an example in Microsoft Help Viewer for ControlDesigner. I copied and pasted the example code into a project UserControl1 and it too does not seem to function. When moving the mouse over the control the outline does not highlight and also the OutlineColor property is not shown in the Properties window. Can someone help? Below is the sample code from Help Viewer. The only difference the test control is called UserControl1 Thank you.
using System.ComponentModel;
namespace TestApp
{
// ExampleControlDesigner is an example control designer that
// demonstrates basic functions of a ControlDesigner.
public class ExampleControlDesigner : System.Windows.Forms.Design.ControlDesigner
{
// This Boolean state reflects whether the mouse is over the control.
private bool mouseover = false;
// This color is a private field for the OutlineColor property.
private Color lineColor = Color.White;// This color is used to outline the control when the mouse is // over the control. public Color OutlineColor { get { return lineColor; } set { lineColor = value; } } public ExampleControlDesigner() { } // Sets a value and refreshes the control's display when the // mouse position enters the area of the control. protected override void OnMouseEnter() { this.mouseover = true; this.Control.Refresh(); } // Sets a value and refreshes the control's display when the // mouse position enters the area of the control. protected override void OnMouseLeave() { this.mouseover = false; this.Control.Refresh(); } // Draws an outline around the control when the mouse is // over the control. protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe) { if (this.mouseover) { pe.Grap
Here's the same code; only more complete, it seems. [ControlDesigner Class (System.Windows.Forms.Design) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.design.controldesigner?view=windowsdesktop-6.0)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
Here's the same code; only more complete, it seems. [ControlDesigner Class (System.Windows.Forms.Design) | Microsoft Docs](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.design.controldesigner?view=windowsdesktop-6.0)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
Yes this is the example where a copied the test code from. I tried this example 'as is' but it did not work. The code in my question is the same; It just uses a UserControl1 that I created in my test project while debugging. I did not include the UserControl1.Designer.cs code which includes the other code. Thank you
-
Yes this is the example where a copied the test code from. I tried this example 'as is' but it did not work. The code in my question is the same; It just uses a UserControl1 that I created in my test project while debugging. I did not include the UserControl1.Designer.cs code which includes the other code. Thank you
It's not the same; it does not have / or you removed the disposing code. Or did you think it just wasn't important so it's: "as is"?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
It's not the same; it does not have / or you removed the disposing code. Or did you think it just wasn't important so it's: "as is"?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
I'm sorry for the confusion. There are 2 files to a UserControl when created from the application: In this case UserControl1.cs UserControl1.Designer.cs The latter file contains the standard Dispose() code which I did not supply since it's just standard code. For arguments sake, I started with the code you referenced 'as is'.. That means I copied and pasted the whole sample into a project file, built it, and tried it by loading it into a from from the toolbox; it did not function as described... 1. When the mouse moves into the control, the control does not show the highlight the border as the MouseEnter() method should do. 2. The property that is added in the designer "OutlineColor" does not show in the grid properties. I've managed to get the debugger to work in DesignMode and set a break points in the MouseEnter() method and the OutLineColor.Set property and the OnPaintAdornments() method. None of the break points are hit when the control is loaded into the form. thanks