| | |
What does this control need?
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
Yeah, I haven't yet learned the art of obfuscation yet... so maybe not.
I changed the inherit from UserControl to Control and and it still worked fine. I then was able to override the Height property successfully.
I could then even easily just set it as a type of my enum. but that led to the problem that all my code that does calculations will have to be changed to cast the enum to an int. and I think I use the height in calculations 20 or 30 times.
and I have no idea what effect it will have on the designer, I will have to look into it. but that is after the movie, thanks for all your help sknake!
I changed the inherit from UserControl to Control and and it still worked fine. I then was able to override the Height property successfully.
I could then even easily just set it as a type of my enum. but that led to the problem that all my code that does calculations will have to be changed to cast the enum to an int. and I think I use the height in calculations 20 or 30 times.
and I have no idea what effect it will have on the designer, I will have to look into it. but that is after the movie, thanks for all your help sknake!
OK! overriding the height works fine when bound to an enum so long as you do some checking to make sure the values set to it follow the values in the enum. Here is an example of how I did it.
now when I drag the resize handles in visual studio, it jumps to the closest setting.
thanks for all the help sknake. Lots to do before its officially finished. but I am well on my way. Just lots of cleaning up to do.
C# Syntax (Toggle Plain Text)
//create height enum public enum ContorlHeight { Short = 36, Normal = 40, Tall = 50 } [Bindable(true), Category("Appearance"), DefaultValue(typeof(ContorlHeight), "Normal"), public new ContorlHeight Height { get { if (base.Height < 38) return ContorlHeight.Short; else if (base.Height >= 38 && base.Height < 46) return ContorlHeight.Normal; else return ContorlHeight.Tall; } set { if ((int)value < 38) base.Height = (int)ContorlHeight.Short; else if ((int)value >= 38 && (int)value < 46) base.Height = (int)ContorlHeight.Normal; else base.Height = (int)ContorlHeight.Tall; } }
now when I drag the resize handles in visual studio, it jumps to the closest setting.
thanks for all the help sknake. Lots to do before its officially finished. but I am well on my way. Just lots of cleaning up to do.
Last edited by Diamonddrake; Sep 19th, 2009 at 10:56 pm.
You should also validate the enum in the Setter property of your application. In this case it will handle an "invalid" enum properly since it tests lengths but it will help smoke out bugs if you ever have an enum parse improperly.
IE this code will work and in my opinion shouldn't:
What I do with enums like that:
IE this code will work and in my opinion shouldn't:
C# Syntax (Toggle Plain Text)
private void button2_Click(object sender, EventArgs e) { SomeCtrl ctrl = new SomeCtrl(); SomeCtrl.ContorlHeight height = (SomeCtrl.ContorlHeight)600; //This line ctrl.Height = height; } } public class SomeCtrl : Control { //create height enum public enum ContorlHeight { Short = 36, Normal = 40, Tall = 50 } public new ContorlHeight Height { get { if (base.Height < 38) return ContorlHeight.Short; else if (base.Height >= 38 && base.Height < 46) return ContorlHeight.Normal; else return ContorlHeight.Tall; } set { if ((int)value < 38) base.Height = (int)ContorlHeight.Short; else if ((int)value >= 38 && (int)value < 46) base.Height = (int)ContorlHeight.Normal; else base.Height = (int)ContorlHeight.Tall; } } public SomeCtrl() : base() { } }
What I do with enums like that:
C# Syntax (Toggle Plain Text)
public new ContorlHeight Height { get { if (base.Height < 38) return ContorlHeight.Short; else if (base.Height >= 38 && base.Height < 46) return ContorlHeight.Normal; else return ContorlHeight.Tall; } set { if (!Enum.IsDefined(typeof(ContorlHeight), value)) throw new InvalidEnumArgumentException("Height", (int)value, typeof(ContorlHeight)); if ((int)value < 38) base.Height = (int)ContorlHeight.Short; else if ((int)value >= 38 && (int)value < 46) base.Height = (int)ContorlHeight.Normal; else base.Height = (int)ContorlHeight.Tall; } }
I just finished another Hue Slider control. This time it is a custom drawn Photoshop Hue slider clone, the only difference was I intentionally made the arrow a little bit larger, It always frustrated me how small the arrow was, I like a larger click region.
I am working on the Saturation and luminance clones as well, and when I have completed them, i will release them with code under a noncommercial license.
Tell me what you think
included in photo, My custom hue slider control, and the photoshop clone slider control.
I am working on the Saturation and luminance clones as well, and when I have completed them, i will release them with code under a noncommercial license.
Tell me what you think

included in photo, My custom hue slider control, and the photoshop clone slider control.
•
•
•
•
I like the idea, but I would like to see an enum for the height. could that be done?
so the height property would no longer be a int, but an emum.
any Ideas how this could be done, I realize all this code is BS, but how could I achieve this?
C# Syntax (Toggle Plain Text)
namespace Slider { public enum ControlHeight { //short is a keyword so changed it small/large small = 18, normal = 25, large = 40 } public class SliderControl : Control { public new ControlHeight Height { get { return (ControlHeight) Enum.Parse(typeof(ControlHeight), base.Height); } set { base.Height = (int)value; } } } }
Is that kinda what you were going for?
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
Thanks Ryshad, I didn't think about using enum.parse, that is a better solution than what I come up with, of course the real take for me was the set method, witch I figured out a good solution for, my goal was to only allow setting specific heights, so even in VS if you drag to resize the control it jumps to the closest compatible height.
Thanks again for the suggestion.
Thanks again for the suggestion.
![]() |
Similar Threads
- News Story: Nokia wants control of your home (Apple Hardware)
- Unable to access my computer, my documents, and control from start bar and run!! (Windows NT / 2000 / XP)
- News Story: Crystal Ball Sunday #9: Intelligent Control (Linux Servers and Apache)
- Using the Datalist Control as a Menu (ASP.NET)
- How to control a CD-Drive (C)
- Tabbed Control Dialog (Visual Basic 4 / 5 / 6)
- Problems with control panel _>Internet options (Windows 95 / 98 / Me)
Other Threads in the C# Forum
- Previous Thread: C# Form Text Box Input to SQL Database
- Next Thread: Vista ThumbnailProvider and IInitializeWithStream
| Thread Tools | Search this Thread |
.net 3.5 access ado.net algorithm analyst applicaions array art asp asp.net beginner bitmap broadcast c# c++ calculator code color combobox concurrency connect contorl control cs4 custom database datagrid datagridview datastructure datetime degrees development disabled drawing e-commerce editor enum excel exectuable file forloop form forms freelance gdi+ http httpwebrequest index keypress label linux list listener listview math messagebox microsoft mobile mouse mysql operator photoshop php picturebox platform post programmer programming read remote remoting richtextbox robot silverlight smoobjects sql sql-server stream string stringformatting text textbox tree user usercontrol validate validation vb video visualbasic visualstudio vulnerability wia windows winforms wordautomation working wpf xml







