The basic idia is simple -
if the checkbox is in normal state => show image1
if in press state => show image2
if in mouse over state => show image3
|
. I try to create 3 state button. This control will will change the image on each of those 3 state ( normal, pressed, mouseOver ). The images of each state will be define as a property from the c# code ==> that mean i will be able to re-use this code and change the properties of the image source. |
changinf images is done by binding the images to the code.
for some reason i dont see anything on the window when i using the control.
i dont see the images change, i dont see the control border and i dont know why.
attached the control code : because i realy dont know what wrong here ...
1. xaml:
Java |
2. C# Code:
Code |
C#
public partial class CheckBoxEx_ : CheckBox
{
public CheckBoxEx_()
{
InitializeComponent();
this.DataContext = this;
}
#region Field
public Image mouseOver;
public Image pressed;
public Image normal;
#endregion
#region Properties
public Image MouseOverImg
{
get
{
return mouseOver;
}
set
{
mouseOver = value;
}
}
public Image PressedImg
{
get
{
return pressed;
}
set
{
pressed = value;
}
}
public Image NormalImg
{
get
{
return normal;
}
set
{
normal = value;
}
}
#endregion
}
kaliappan Ravikumar29 reputationPosted Oct 12, 2010, 10:48 PM EDT
Add All the Three Images in ImageList
Now assign that ImageList to checkbox image List
Just Change Inageindex when u need
ImageList imglst = new ImageList();
imglst.Images.Add(global::ListBoxSample.Properties.Resources.Workflow);
imglst.Images.Add(global::ListBoxSample.Properties.Resources.Logo);
imglst.Images.Add(global::ListBoxSample.Properties.Resources.emulator);
checkBox1.ImageList = imglst;
checkBox1.ImageIndex = 0;
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
checkBox1.ImageIndex = 2;
checkBox1.Text = " emulator";
}
}
private void checkBox1_MouseHover(object sender, EventArgs e)
{
checkBox1.ImageIndex = 1;
checkBox1.Text = " Logo";
}
private void checkBox1_MouseLeave(object sender, EventArgs e)
{
checkBox1.ImageIndex = 0;
checkBox1.Text = " Workflow";
}
Yanshof24 reputationPosted Oct 13, 2010, 12:01 AM EDT
Its work fine.
But i really want to know ( and learn ) why my original code is not working fine ? What i did wrong ?
Suthish NairRank #92 · 22.8K reputationPosted Oct 13, 2010, 12:57 PM EDT