I am programming winforms using c# and vb.net.
I love the arrows used in coderush.
for those who have not seen coderush arrows ,please see this image.
(source: aspnetpro.com)
http://www.aspnetpro.com/productreviews/2004/08/asp200408bn_p/asp200408bn_p_image002.jpg
I want to have something similar in my program.
only difference is i will be using it to highlight textboxes and buttons.
I only want the arrow , the text on the arrow is not important.
So maybe I need to make a general function like
DrawHighlightArrow(controlname)
and it will somehow manage to draw an arrow next to that control
Please suggest a nice geeky way to solve this problem in C# or Vb.net
Thank you
Anna
Override the OnPaint method on the Form, and use the DrawImage() method on the object from the PainteEventArgs.Graphics property to draw a bitmap of an arrow.
You could create a custom form with a transparent background, paint your arrow on it using GDI+ (using marxidad's technique above, or by just dropping a PictureBox on it and handling the Paint event).
Then just instantiate a new instance of the arrow form over the top of your existing "parent" form (you might want to set TopMost to true) and start a Timer to fade it out.
The only thing to be careful of there is...
cleaning up properly if you prematurely close the "parent" form, and...
passing through any click events to the "parent" form.
There is a really nice library called Locus Effects here. Go check it out, it does exactly what you want it to do.
Related
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?
At this point, I almost never want to design a control with rich design-time support again. That said...
I am already overriding the SnapLines property in my ControlDesigner-derived class to manually forward out various snaplines from the child controls of my control -- the text baseline (pink) snap from the labels and comboboxes; the text inset snap from the labels; the top, bottom, left and right snaplines from the comboboxes. Those snaplines activate when the control itself is moved around on the form and when other controls are moved around it.
What I need is the ability to tell the designer to activate the snaplines and then deactivate them while I'm doing an internal move or resize of the underlying controls.
My comboboxes are resizable through overrides of OnMouseDragBegin, OnMouseDragMove, and OnMouseDragEnd in my control designer. The magic bullet I'm looking for is something I can call in Begin to tell the designer to show the snaplines and something in End to tell it to stop.
Allowing people to resize and move the internal controls at design time is kind of useless if they don't show snaplines for each other or for external controls.
As with stuff like this, it's incredibly hard to search for. I've found one post on a forum where someone asked this exact question that had (of course) no responses. That's about it.
Obviously the issue of actually snapping to the snaplines when/if they're shown remains. Just being able to see them would be a nice start.
Any ideas?
The best way to do what you want todo is to create a Design Surface MSDN Reference
I've used this to create my own design surface for my application so that the clients can customize the forms.
Hope this helps,
Johan J v Rensburg
I´m using WinForms. I want to make a little class, which modifys controls to show it´s working.
I want to draw an overlay over for example a button. It should be a half-transparent gray.
After that i want to draw a ProgressBar on over it (in the center). Similar to This, except using a progress bar.
How can i realize this? I don´t want to set the position of the progressbar, just drawing it on the other one.
How could i do this?
Thanks :)
I have done something similar before.
You need to use Button.DrawToBitmap(Bitmap, Rectangle) to get the image of the button. Then make the Bitmap grayscale (there are multiple algorithms available for this; I have used the last one successfully although probably not originally from this site).
Now, I did this with an entire form instead of a button, but I disabled the form, and then covered the entire form with an image of itself, altered and then covered it with the progress bar (itself in a panel with other controls).
You could just as easily disable the button, cover it with a panel containing the image and the progress bar on top of it.
I feel quite limited by the default ContextMenuStrip, as it only can contain buttons, and no Controls.
I was wondering that for a long time, and I already tried it, using forms, but it never really worked out.
I already have I idea on how to set the whole thing up, with events and items. The only problem I have is the paint method.
When you open a ContextMenu (ContextMenuStrip) you can set its position on the mouse cursor, and it will be there, even if that means that it goes beyond the active form. (So I can't use the Controls Class as inheritance, as they can only draw themself as a part of a form.
Now I thought to use the Form Class as a base for my ContextMenu, but those where placed on the screen randomly.
So what I actually need is a class (or something similar) that can draw itself, without problems, and can be placed accurately on the screen.
Any hint would be nice, thanks.
Greg the Mad
Your first statement is false -- you can have a TextBox or a ComboBox in a ContextMenuStrip.
MSDN ToolStripComboBox
MSDN ToolStripTextBox
From the designer there is a small drop-down arrow when your mouse is in the "Type Here" box (sometimes hard to click) that will allow you to change the type.
If you are looking to allow for any type of control to be displayed in a top down fashion inside of a container to be positionable... you could always make a custom control using FlowLayoutPanel. With it's properties FlowDirection=TopDown and WrapContents=False to keep a vertical approach. This will handle your "menu" basics and your new control can expose whichever events you wish from each Control. You will have to handle the logic of showing the panel and positioning with it's Location property as well.
I forgot to address the issue with drawing outside of the parent form. Notice that ContextMenus are smart and when they reach a boundary of their parent they draw away from it. You should logically be able to draw in the correct direction (Up/Down or Left/Right) from any right mouse click. Per your attempt with a Form, set StartPosition=Manual then prior to calling Show() or ShowDialog() set it's Location property respective to the X and Y parameters provided in the event args of MouseClick.
I'm creating a plugin to a software that skins the form I created. However, the button are not skin based on them and a standard gray button is shown. Asking on the software forum pointed me that .NET forms control are owner-draw and therefor my button won't redraw with the correct style instead of creating a non ownerdraw button.
All controls in the system.windows.forms namespace seem to be ownerdraw.
So how can I create a standar C++ PUSHBUTTON in .NET?
Currently codding in C# if that helps.
Thx
The controls in Windows.Forms are not owner-drawn, but rather system-drawn. This is how Windows paints them by default, be it a Button, TextBox or what else. You can override the drawing either by specifying that the control should be owner-drawn (that is: you are responsible for drawing it) - some controls support that, a couple of them even with a finer granularity (see ListView), or you can override the painting completely in OnPaint event of any Control descendant.
Your question is rather confusing - as I understand the buttons you create in your plug-in are not skinned. Obviously what you need is to tell this skinning framework to paint these buttons. There probably is or should be some component that you drop onto the plug-in form or method you call that will inject the skinning painting routines into your plug-in.
It sounds like you want to set the FlatStyle property of your button to FlatStyle.System. Windows Forms buttons are indeed, by default, owner draw at the WinAPI level, and are drawn by the framework.
Have you tried setting the FlatStyle to another value, such as Flat or Popup, just to see if that stops it being skinned?
also setting Flaststyle = Standard (as opposed to system) might solve your problem
Standard was the default and therefor wasn't reskinned. When setted to flat, I get a background color and a foreground color, but lose the round corner end the hover effect suggesting that the control is not reskinned and just color style is applyed. Flat is the only version not grey, but I lose some of button feature (hover, round corner)