What does this control need?

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Mar 2008
Posts: 330
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 39
Diamonddrake's Avatar
Diamonddrake Diamonddrake is online now Online
Posting Whiz

Re: What does this control need?

 
0
  #11
Sep 18th, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 330
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 39
Diamonddrake's Avatar
Diamonddrake Diamonddrake is online now Online
Posting Whiz

Re: What does this control need?

 
0
  #12
Sep 19th, 2009
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.

  1. //create height enum
  2. public enum ContorlHeight
  3. {
  4. Short = 36,
  5. Normal = 40,
  6. Tall = 50
  7. }
  8.  
  9. [Bindable(true), Category("Appearance"),
  10. DefaultValue(typeof(ContorlHeight), "Normal"),
  11. public new ContorlHeight Height
  12. {
  13. get
  14. {
  15. if (base.Height < 38)
  16. return ContorlHeight.Short;
  17. else if (base.Height >= 38 && base.Height < 46)
  18. return ContorlHeight.Normal;
  19. else
  20. return ContorlHeight.Tall;
  21. }
  22. set
  23. {
  24. if ((int)value < 38)
  25. base.Height = (int)ContorlHeight.Short;
  26. else if ((int)value >= 38 && (int)value < 46)
  27. base.Height = (int)ContorlHeight.Normal;
  28. else
  29. base.Height = (int)ContorlHeight.Tall;
  30.  
  31. }
  32. }

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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,242
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 577
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast

Re: What does this control need?

 
0
  #13
Sep 20th, 2009
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:
  1. private void button2_Click(object sender, EventArgs e)
  2. {
  3. SomeCtrl ctrl = new SomeCtrl();
  4. SomeCtrl.ContorlHeight height = (SomeCtrl.ContorlHeight)600; //This line
  5. ctrl.Height = height;
  6. }
  7. }
  8.  
  9. public class SomeCtrl : Control
  10. {
  11.  
  12. //create height enum
  13. public enum ContorlHeight
  14. {
  15. Short = 36,
  16. Normal = 40,
  17. Tall = 50
  18. }
  19.  
  20. public new ContorlHeight Height
  21. {
  22. get
  23. {
  24. if (base.Height < 38)
  25. return ContorlHeight.Short;
  26. else if (base.Height >= 38 && base.Height < 46)
  27. return ContorlHeight.Normal;
  28. else
  29. return ContorlHeight.Tall;
  30. }
  31. set
  32. {
  33. if ((int)value < 38)
  34. base.Height = (int)ContorlHeight.Short;
  35. else if ((int)value >= 38 && (int)value < 46)
  36. base.Height = (int)ContorlHeight.Normal;
  37. else
  38. base.Height = (int)ContorlHeight.Tall;
  39.  
  40. }
  41. }
  42.  
  43. public SomeCtrl()
  44. : base()
  45. {
  46.  
  47. }
  48.  
  49. }

What I do with enums like that:
  1. public new ContorlHeight Height
  2. {
  3. get
  4. {
  5. if (base.Height < 38)
  6. return ContorlHeight.Short;
  7. else if (base.Height >= 38 && base.Height < 46)
  8. return ContorlHeight.Normal;
  9. else
  10. return ContorlHeight.Tall;
  11. }
  12. set
  13. {
  14. if (!Enum.IsDefined(typeof(ContorlHeight), value))
  15. throw new InvalidEnumArgumentException("Height", (int)value, typeof(ContorlHeight));
  16.  
  17. if ((int)value < 38)
  18. base.Height = (int)ContorlHeight.Short;
  19. else if ((int)value >= 38 && (int)value < 46)
  20. base.Height = (int)ContorlHeight.Normal;
  21. else
  22. base.Height = (int)ContorlHeight.Tall;
  23.  
  24. }
  25. }
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 330
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 39
Diamonddrake's Avatar
Diamonddrake Diamonddrake is online now Online
Posting Whiz

New Update PhotoShop Hue Slider Clone

 
0
  #14
Sep 30th, 2009
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.
Attached Thumbnails
myHueSliders_withPS.JPG  
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 378
Reputation: Ryshad has a spectacular aura about Ryshad has a spectacular aura about 
Solved Threads: 68
Ryshad's Avatar
Ryshad Ryshad is offline Offline
Posting Whiz

Re: What does this control need?

 
0
  #15
Sep 30th, 2009
Originally Posted by Diamonddrake View Post
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?
Your code is almost there for using an enum:

  1.  
  2. namespace Slider
  3. {
  4. public enum ControlHeight
  5. {
  6. //short is a keyword so changed it small/large
  7. small = 18,
  8. normal = 25,
  9. large = 40
  10. }
  11. public class SliderControl : Control
  12. {
  13. public new ControlHeight Height
  14. {
  15. get
  16. {
  17. return (ControlHeight) Enum.Parse(typeof(ControlHeight), base.Height);
  18. }
  19.  
  20. set
  21. {
  22. base.Height = (int)value;
  23. }
  24.  
  25. }
  26. }
  27. }

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
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 330
Reputation: Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough Diamonddrake is a jewel in the rough 
Solved Threads: 39
Diamonddrake's Avatar
Diamonddrake Diamonddrake is online now Online
Posting Whiz

Re: What does this control need?

 
0
  #16
Oct 1st, 2009
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.
Reply With Quote Quick reply to this message  
Reply

Tags
c#, contorl, custom, drawing, gdi+, usercontrol

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC