I am drawing rectangles inside a picture box, based on data that is being pulled from database. Everything works correctly, now my question is, is that possible to select created rectangles? I'd like to be able to select the rectangle and change the data in it.
I guess one of the options will be to along with rectangles display the list of them, and select them from there.
If anyone has any experience with this, I would greatly appreciate a tip.
Thank you,
H
You could, instead of adding directly a rectangle to the form picture box, create a custom windows forms control that holds a rectangle, and add it to the form directly, or to some kind of container.
There you can easily handle the click event of your custom control.
Look here for help on how to do this.
Related
I have been using the Windows Touch Scratchpad Sample in C# (MTScratchpadWMTouchCS) example located at https://msdn.microsoft.com/en-us/library/windows/desktop/dd940546(v=vs.85).aspx and it works beautifully.
What I would like to do, is set the Form.BackgroundImage to a BMP file, which works fine at the moment.
Next, I would like to be able to 'scribble' over the form using a touch device - also working without issues at the moment.
Then, I to use a Button to use 'DrawImage' to place another BMP file (or Bitmap object) of an 'Emoji' (for example) onto the form, and be able to retreive it using the Form.Image property. Also working fine.
Lastly, and this is where my issue is - I need to be able to 'grab' the Form.Image property and be able to save it to a file. This almost works, in that it grabs the 'emoji' but it does not grab the 'scribble'
So looking at the Example linked above, it appears that it does not 'draw' to the Image property of the form. Is there a way I can acheive this? Graphics have always eluded me.
First of all, that's really a lot of questions so you should deal with them one at a time. But to address the general aspects of your problem:
Don't work directly on the form. Add controls to the form that you can interact with. For instance, I would add a Panel and make it take up the entire client area (Fill mode). Then, I would add controls to that Panel, such as a PictureBox. You can either subscribe to the controls' Paint events, or even inherit your own control and override the Paint event for full control. Depends on how much you need to get a hold on.
I have displayed an image in a Windows form. The user can draw a rectangle on top of this. When the user releases the mouse after drawing the image, I need to display a few buttons, similarly to showing a tooltip.
So far, I have:
Created a new WinForm named Toolbar
Removed titlebar
Added tooltip control on the WinForm
Added 4 buttons
Being an ASP.NET web developer I perceive the following items as missing:
Handle MouseUp event
Get co-ordinates of the mouse release location (say x1, y1)
Render my Toolbar Winform with top position as (x1, y1)
Let the respective buttons handle their responsibilities in their event handlers
Can you please help me validate my approach and show some pointers for the code?
You can use ContextMenuStrip (info from MSDN)
With 4 Items and just show it on MouseUp event with:
contextMenuStrip1.Show(Cursor.Position);
Two approaches:
This. You create a Popup form, which will be automatically hidden similar to popup menu and can host controls (buttons).
Display (draw) buttons inside your control, on top of its content (on top of graphics which you drawn), process mouse clicks, perform operations accordingly. Most difficult will be to draw nice looking buttons, to example, by using VisualStyleRenderer (xp-style).
Do not aks big question (containing many small one), rather try something, if it doesn't work or you are not satisfied with results, then come here and ask question (while also telling what you are trying to do). This way you will get help very quickly.
Hello,
Above is the program I am writing. On the right panel is basically two custom controls (the blue rectangle area) I created and just added them as controls to the background panel control when this winform program loads.
I used MS paint to draw out the pop up balloon that I want to see when my mouse enter this control's area. I want to do the following:
1. If mouse enter the control area, the yellow area balloon pop up and populate with the information of that specific control
2. If mouse move out of the control area, the pop up balloon disappear.
Can this be done with Winform application? I looked around and found out about Tooltip class but so far from researching I don't know if it does what I want to do.
I could be wrong but googling around gave me the impress that Tooltip offers very little in term of style. Ideally I want to make this pop up balloon into almost like a border-less pop up window where I can put image , font ect.....at will. Also Tooltip works if you hover over a button or specific field whereas I want the entire control area.
Can this be done? I appreciate if you can point me to any work around if there is one.
I wrote a comment, but I figure I'll expand it into a full answer. This is assuming you want a new control, which isn't a tooltip, for maximum customizability. I did something similar to this for work recently, to act as a non-modal info popup that disappears when clicked.
Creating a Custom Popup Form
What you want is essentially a floating popup that appears over your form, which means you'll want to define a new Form object, rather than a UserControl, as it won't actually be embedded within your other form.
Give it a multiline, non-editable textbox that you can fill with the information you want to populate, then simply call a new instance of the form on your Mouse_Enter event. Close it upon Mouse_Leave.
Adjusting The Style
You'll have to play with it a bit to get it to actually act like a popup and not just a window. I'd recommend setting it to a non-modal popup, and removing the border. You can write a function to automatically size it to its contents. I don't imagine you'll want the user manually resizing it.
Some other things to look into would be overriding the CreateParams property that comes with the basic Form object. You can force DropShadows and TopMost forms without making the form modal. Overriding ShowWithoutActivation to always return true will prevent the form from stealing focus when it pops up.
I'm not sure if you can pull off rounded edges like you have in your mockup. Perhaps you can pull it off with some wizardry in the OnPaint() function, but I couldn't tell you how to do it.
It might be a bit of a pain for fiddling around with, but you can get some good functionality and appearance out of it. If you think you can pull it off acceptably with the ToolTip class, go for it. It took me about a week to get my notifications where I wanted them (though I added several features that you probably don't need to worry about).
Examples
Some keywords to look up in related searches would be Toast Notification and Non-Modal Popup. This might be some use:
http://www.codeproject.com/Articles/442983/Android-Style-Toast-Notification-for-NET
Since you already have implemented custom user controls you might want to try it again. Make a control that is that style and color, changes it's size based on it's text. You can feed it information (such as the text to display) from your existing user control object. You can also have the mouse enter/leave code reside in your first user control.
If you're not sure how to make a rectangle with round corners you can either make it on the fly using a graphics object (which will turn into a bitmap on the screen) or make it how you want it to look in GIMP (or photoshop if you have it) then use that image as the background on your user control. Make the default background transparent (so your voids above the round corners are not grey). If you make a pre loaded image you'll need to be aware you will only be able to scale it equally in Y and X directions. unequal scaling will make it look distorted.
Can you use the Mouse_Enter event on the control?
First of all, here's some concept art for how this custom list control must look:
http://img816.imageshack.us/img816/1088/customlistctrl.png
Each list item is fairly complex and turns into an "edit interface" when the mouse hovers over it. I also have PNG image files for every skinning detail of this thing, including the scroll bar.
What is the best approach to get started implementing this? Would I create a custom control and simply render all of this in GDI?
Could I make the list control a transparent clip region with a scroll bar? For the individual list items, would I simply use a textured panel as the backdrop for each item and place existing .NET forms (like combo boxes, buttons, edit fields, etc) as children of that?
I've never had to create something this detailed before.
If you want your control to look exactly like the given picture (which is nice), you will end up drawing much of it, if not all of it, yourself. One possibility is to subclass each control being used and override the OnPaint method to do your custom drawing. This assumes a design where everything in your picture is an individual control.
I myself might make each row a separate UserControl-derived class, perhaps with an internal constructor so users of your control can't create the row directly. Within your SkinnedListRow class (or whatever name), you could have each of the subcontrols. By the looks of things, the row contains three controls that display numbers and one that displays any kind of text.
For the editing portion, derive another UserControl that contains all the controls you picture. Both the display controls and the editing control are owned by the SkinnedListRow from above, so it knows how to load data from one set into another.
You have a good amount of work in front of you, but your idea looks nice. Good luck.
Does anybody have an example on how to type letters onto a form, like in a graphics program? When I click in a position on the form, I want to be able to start typing and have my text show up on the form.
See this answer to an earlier question:
Need help creating control to display data
Down at the bottom of the answer are links to a sample application and its source code. This sample shows how to do editing in-place of graphically-draw text. The app basically moves a textbox over the graphics to allow text entry and editing, and then when the user clicks away from the textbox the box is made invisible and the entered text is drawn onto the control surface. You can modify this technique to do what you need.
Unfortunately I cannot give the exact example that you're looking for. However, I can recommend that you to look at open source projects and try to find an application that does something similar what you need. Then you simply can look at the source code.
You can start with sites like CodePlex and SourceForge.
With a quick search on CodePlex I was able to find two application that might help you:
Image to Text Art
Text Image Generator
If you like to write something on your form you can use GDI+ features.To do so you can override the paint method of your form like this:
protected override OnPaint(PaintEventArgs e)
{
}
PaintEventArgs class has a reference to a graphics object that let you do some graphical stuff on your form.
For your task you can use DrawString to write on the surface of your form
BTW you should be informed that every time the form surface becomes invalidated it will be painted again and maybe you want to keep what you want to write on your form in a list so that you can write them every time the form is painted again.