Remove a drawn object in Windows Forms - winforms

I have created a Windows Form, in which I am drawing 3 objects(Rectangle, Circle, and Line). I have 1 base class for all of them and separate classes for each of the objects. All objects are stored in an array.
In Windows Form has been created a Panel in which we draw and 3 buttons to draw an object.
What I need is to select an object with a mouse click and highlight it, then with pressing the fourth button to delete it.
The problem is I don't know how to select the object which has been clicked...
Any guides or piece of code, how to do it?

On your onClick event cast the sender parameter in your Object type something like this:
ObjectBeingClicked objectName = (ObjectBeingClicked)sender;
Or another example:
Rectangle rect = (Rectangle)sender;

Related

scichart3d geometry object select Is it impossible?

I want to implement in scichart3d viewport3d geometry object select
entity object (viewport3d geometry object) selection is not Support.
so i think I tried to put a series in the inside of an object so that I could select it.
but series overwritten with viewport3d object are not selected.
so I made it disappear temporarily when I clicked on an object, but it was not practical enough.
Below is an example I wrote.
I hope I can help you see this.
enter link description here
Is there any other way to implement the ability to select viewport3d geometry objects?

Winforms PropertyGrid per-GridItem row height

I'm using the Winforms PropertyGrid; the target of the SelectedObject includes a property of type Image. Everything is fine, except that with all items the same height, the image is too small to see properly. I'd like to have some control over the height of grid items such that the image can be displayed a bit larger. One other detail is that the SelectedObject of one PropertyGrid control may be assigned an object of any of a variety of different classes (which may or may not have image properties), so I'm hoping the height can be driven by data in the instance of the SelectedObject itself, rather than making it a static behavior of the control, although I'd settle for a custom attribute of the image property to make the item height at least class-specific if it can't be instance-specific.
How can I do this? Custom attribute? PropertyGrid event? Something else?
As Simon commented on your question, this is not possible to have a custom height for a GridItem.
You have 2 solutions to be able to show an image with a reasonable size:
You can code your own UITypeEditor. That way, the user would just click the down arrow and see a nicely sized image in the dropdown box.
Sorry for the plug but I think it directly answers your question: only 3rd party PropertyGrids may allow you to get variable size rows in the grid. Smart PropertyGrid.Net is one of them. You set a HeightMultiplier to the row so that it expands on let's say 4 rows. Then you code your own Look class that handles the drawing of the image the way you want in this space.

Tool to know Windows Form Application's Form fields

I am working on a WinForm Application.
The Form has many fields/components but is poorly built.
for example a field is used as user name on one case and used as folder path on the other case. Code is quite poorly maintaned.
Is is possible that when i run the application and GUI appears, i can use a tool like 'spy++' which can show me 'names' of the components (not ids). For instance the name of a button or name of a label.
Or if i can use SPY++ for 'names' please tell me?
I would solve the problem by adding a ToolTip control to your form and iterating over each control and adding a Tool Tip message to each control that is the name of the control.
First, add a ToolTip object to your form (from the Tools section of the designer.) You can rename it, but for the sake of my demo, I left it as the default name toolTip1.
Next, add a method similar to the one I'm posting below to the code page of your form. (I'm assuming this is for C# but the code is simple and can easily be modified for VB or C++).
public void AddNameToToolTip(Control c)
{
toolTip1.SetToolTip(c, c.Name);
foreach (Control child in c.Controls) AddNameToToolTip(child);
}
Finally, from within the Form constructor, add the following line of code after the call to InitializeComponent().
AddNameToToolTip(this);
This will add a ToolTip message to each control in your form. All you should have to do is hover your mouse over each control and the ToolTip will pop up a message after a second or two displaying the name of the underlying control.
Alternatively, you can recursively adding a MouseHover event to each control and when the event is fired, write the name of the control to the debugger. This would also work if you are already using a ToolTip control within your form.

Where do I find those WinForms controls?

I am looking for a WinForms control that, I believe, in the days of VB 6.0 (I can't remember if it was VB 6 or .NET 1.1) used to be called the ButtonImage or ImageButton or some such. Whatever it was called is not important.
What it used to look like and behave like is the important thing.
If you open Control Panel -> Add Remove Programs in Windows XP, the buttons on the left Change or Remove Programs, Add New Programs, etc. use tat control. I want a control that looks like that. It's a button with an image but stays pressed when it is selected.
Secondly, I am looking for a splitter. I see one in the Toolbox in Windows Forms apps, but when I try to change its size at runtime, it won't.
Do I have to use a SplitterContainer first or something?
You may make use of RadioButton control or CheckBox control.
Add the control and change the Appearance property of RadioButton to Button. Add a BackgroundImage to that.
Unfortunately this control doesn't exist in Windows Forms. You will probably find one in commercial control libraries, look for Outlook-type menus.
For the splitter, you have to use a SplitterContainer, which is two panels separated by a splitter. Then you add your controls on both splitters and will be able to move the splitter and everything.
For starters you can make the button use an image by tweaking the properties like so
Button1.Text = ""
Button1.Size = New Size(100, 100)
Button1.TextImageRelation = TextImageRelation.ImageAboveText
Button1.Image = My.Resources.Image1
That would make the button look like this
You could also swap out the image every time the user clicks with the buttons click event.
Make sure to replace image1 and image2 with the real images.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Image = image1 Then
Button1.Image = image2
Else
Button1.Image = image1
End If
End Sub
You if you want the image to border and hover to be different try messing around with the button.FlatStyle = flat and the FlatAppearance property's.

Loosely couple a modal dialog - is this possible?

I have a winforms custom UI control library which contains a control for displaying modal dialogs Picture-in-Picture.
This custom control receives as a parameter a pointer to the control which has initiated it's display. So they are tied together. This allows the control to be modally displayed over the window which launched it.
Dim f As New PiPCustomDialog 'this form wraps another form PictureInPicture style
f.FormToLoad = New PrintOptions() 'this is the form the user will interact with
f.Owner = Me 'used to determine the size of PiPCustomDialog
Dim dr As DialogResult = f.ShowDialog(Me) 'shows PiPCustonDialog coating, f's OnLoad event initiates display of FormToLoad centered within.
The fact that this control requires f.Owner to be set is what is stinky. User32.dll has a function GetActiveWindow() which would maybe allow the control to be more self-sufficient.
Anyone out there who would like to teach this old dog a new trick? I want to learn a better way.
I'll use this solution for now:
Remove any validation that requires
owner to be set before showing the
form modally.
if owner isn't set inside the class that is transparent cover
(first form) - do a system call into
GetActiveWindow to get owner so the size of the window can be set.

Resources