I need to build a WPF control that looks somehow similar to this:
alt text http://img251.imageshack.us/img251/6857/circle.png
Where each color should be clickable and resizable (or selectable).
This control will be used to set modes on the hours of a day.
I've thought about making 24 buttons that would be arranged in a circle:
alt text http://img684.imageshack.us/img684/2184/buttonsk.png
Another idea was to draw a complete circle and calculate user mouse click's position for the selection and draw several circles to represent the data.
Any other/better ideas on how to build this?
(please excuse my poor drawing).
I think you would get odd edge-effects with multiple overlapping or touching controls. So I would make a single custom control to do this. It would convert the mouse position on button down to a slice, and then do the appropriate action.
With a single control, you could also come up with a rational way of dealing with keyboard input and for showing selection and allowing for multi-select behavior.
It sounds like you want a customized ListBox (multiple items that are selectable/clickable). For the layout you would want to use some type of RadialPanel as the ItemsPanel. You probably also need to change the ItemContainerStyle to make your ListBoxItems look like what you have above, probably with some triggers to change colors based on selection state. Depending on what behavior you need from your items you may need to create custom ListBox/ListBoxItem derived custom controls but in a lot of cases the built-in behavior will get you a long way. To reuse it as a single unit you could wrap up the ListBox with its 24 hour items and customized templates in a UserControl and expose the selection data in whatever form you need as a Dependency Property (like an IEnumerable of the data items representing the selected hours).
Does that help you get started?
Related
I have a chart with multiple chart areas and I want to have a listview where the user checks different signals, that are being plotted in the areas.
Since I want some signals to be displayed in more than one chart areas, I need the listview to reset every time the user selects a different chart Area.
To achieve this I think it is a good idea to create a new listview every time the user selects another chart area and bring the new to front.
My question is , how can I create multiple listviews at the exact same location, and also if someone has a better idea to this.
As you know, you can define the listview in code and do all the styling by hand or you can create a customControl for that.
But then, when the load event of your main form is fired, you create all the listview/customListViewObjects that you need and place them in the same location with the same size by setting their Location and Size property. Finally, you can use BrintToFront() on the required listview when an area is selected.
There are some other ways, but they aren't beautiful in winforms.
A) you can create a tab control with N tabs, then place a listview in each tab and set the tabControl style to the tab header/title is not shown. But as far as I remember, the tabControl will add a border frame that your cannot get rid of.
B) If you don't have many areas and its number is not going to change, you can create the listviews manually in your form editor, and place them wherever in your form (with the appropriate parent, of course). Then in your load event, you can set their location and size properties to the one you need. This is kind of ugly and you may see the controls moving when the form is loaded if you are not careful.
On the other hand, you can just have one listview and then, when the area is clicked you can reload all its child controls for the different signals.
I have created a custom control of my own and i am in a need of making this custom control as a ToolTip for the Labels or Buttons.
But i could not find a way to set the Custom control as ToolTip.
Anyone please help me on setting the Custom control as ToolTip.
Note:
I don't need solution with showing the Custom Control in mouse_hover events of controls.
Please suggest me ideas to make the custom control as default ToolTip in standard way.
Regards,
Amal Raj
I assume that you already know about overriding the paint event, so I won't go into that. If you want anything a bit more complicated, deriving from the ToolTip control to extend it for your purposes won't make much sense since you'll run into restrictions quite fast.
What you should do is implement your own ToolTip control by reusing some important bits from the original one. If you're feeling adventurous you could follow these steps to get started. I'm going to refer to your custom control as tooltip from now on:
If you want to show custom text or something else for each control that uses your tooltip, you need to implement IExtenderProvider in your class. Here's more about it.
You need to keep track of controls that are using your tooltip and the custom values you've set for them. Internally, Windows Forms tooltip uses a HashTable for that purpose. Key is the control showing your tooltip and value is the tooltip text (or something else you want to tie to your tooltip).
If you want to have more than just one string to show (title, description, image etc), you can have multiple HashTables.
When adding the tooltip to a control, subscribe to mouse events (enter, move, leave) to keep track of when to show the tooltip. If you want to have a delay before showing the control, you need to use an internal timer to keep track of time.
You'll most likely want the tooltip to extend outside the main form's boundaries. You could wrap your tooltip inside a headerless form or an alpha blended form to allow other shapes than rectangle.
Those are the very generalized first steps. In reality, there's quite a bit more to be done. It's been a few years since I implemented my custom ToolTip control so I might be forgetting something crucial. However, if you spend some time poking around the code of Windows Forms's ToolTip class, you'll get quite a good idea of what's going on behind the curtains.
I haven't reviewed the code myself but judging from the ratings, this article will give you a good starting point too: A ToolTip with Title, Multiline Contents, and Image. It's in VB.NET but you can easily convert it to C# by using Telerik's converter or any other.
I am in need of a class that mimics a TextBox control but is not a Control, but instead a custom drawn component or element.
Creating one feels like re-inventing the wheel since I see them everywhere. For example, in any modern web browser the text boxes are not controls. Most Winforms controls, especially ToolStrip controls such as ToolStripTextBox, have elements which behave like text boxes (but are not Controls).
I assume that Microsoft doesn't reinvent the wheel for each control they make it. But most likely their code is proprietary and not public.
Does any one know of an open source solution for this? I am experienced with GDI+ drawing but a text field is not a trivial task when you consider caret positioning, selection, and inserting text.
Any pointers on how to go about writing the code myself would be appreciated, such as how to calculate the character at a given point. Should I create a lookup table for the measured width of each possible character? Or loop through MeasureString to take into account formatting space?
You may find the code you need inside this article/project. http://www.codeproject.com/Articles/161871/Fast-Colored-TextBox-for-syntax-highlighting
Why must it not be a Control? If you're using Windows Forms, it is far more likely that you really want a control.
Common cases where this type of question might come up are Grid editing. Instead of a non-control TextBox, what normally happens is that the grid displays simple text in the grid until the user focuses on that grid. At that point a temporary, real TextBox is inserted for editing. Leaving that cell throws the TextBox away and the possibly-changed text is now displayed by the Grid.
I assume your situation is similar. If not, please explain your goals.
What I want to create is a list view that will resize itself in order to show all items. Normally I would use AutoSize, but this won't work here. Any other options how can I make ListView expand and shrink to fit all?
You will have to manually calculate your desired height and set it as items are added/removed.
Detecting item addition or removal isn't directly supported - so you'll either need to create your own Add/Remove Item calls for clients to call, or handle LVN_INSERTIEM type messages from WndProc.
Auto-sizing controls are usually trickier to use - as you have to track Min/Max sizes, allow room on the owner, and usually add to an awkward usability point for users. Only do something like this if typical solutions (i.e. scroll bars) truly can't work for your need.
"AutoSize" property is not supported for the "ListView" control. As #JohnArien mentioned, you will have to programmatically re-size your list view control's size according to the number of items available. But be warned that this may not be a good idea in terms of visual appeal of the Form. Your form design might look ugly if you change the size in run time. More over these types of controls are expected to expand their client area within the given size with the help of scroll bars. I would strongly suggest you to reconsider this option.
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.