I see it's very simple in design and this is good, if it does its functionality well so you don't over care about its design.
Nice work, Diamonddrake
Ramy Mahrous
Postaholic
2,196 posts since Aug 2006
Reputation Points: 480
Solved Threads: 276
Pretty :)
The top one looks a little funny on the far left. It looks like the area to the left of the slider knob is a "stop" of some sort. It looks like a block to me.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
The button's height/size aren't marked virtual in this case but you would want to declare the properties yourself. Hiding members like I have done here isn't a good solution, but it is a good example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace daniweb
{
public partial class frmButton : Form
{
public frmButton()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
button1.Height = 800;
}
}
public class ButtonEx2 : Button
{
public const int MAX_SIZE = 50;
public ButtonEx2()
: base()
{
}
public new Size Size
{
get { return base.Size; }
set
{
base.Size = new Size(value.Width, Math.Min(value.Height, MAX_SIZE));
}
}
public new int Height
{
get { return base.Height; }
set
{
base.Height = Math.Min(value, MAX_SIZE);
}
}
}
}
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
That depends on how your control is implemented, ie if you descended from a .NET implemented control (panel, progress bar) or did you build everything from the Control class and up?
If you want your own custom controls you are better off starting at "Control", making your own "BaseControl", and then create your custom controls from there. The controls provided for .NET don't have all members marked as virtual (such as my example) and so you can never fully customize them.
Do you mind posting code or uploading a project with one of your controls?
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
You know if you release an .exe we can use the reflector and decompile it, right? :)
You should inherit from control and do your control from scratch. Again you can use the reflector to decompile the .NET framework and rip the code off for standard controls and customize it from there.
Stay away from user controls for new controls like buttons and stuff. They're handy if you have a "custom search drop down box" that has complicated databinding etc etc then you could defined a usercontrol for the single project and drop it on forms. But you shouldn't use a user control to make new controls for a toolbox item.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
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:
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:
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;
}
}
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
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:
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?
Ryshad
Nearly a Posting Virtuoso
1,307 posts since Aug 2009
Reputation Points: 512
Solved Threads: 246