Click here to Skip to main content
15,885,895 members

Comments by Bjørn (Top 14 by date)

Bjørn 1-Aug-18 3:38am View    
Hello ranio, I cannot recreate this behaviour. The Base64 representation of 16 bytes must always be 24 characters long (as it uses only 6 of 8 bits) and using your example code I always get exactly 24 characters for the Base64 encoded key which always decode back to exactly 16 bytes. Do you use different code than posted above? Or do you do anything else with Key before it is written into keyStr?
Bjørn 30-Jul-18 11:30am View    
Hello ranio, what exactly is your question here? Are you asking why there is a difference in the length of the byte array and the Base64 string?
Bjørn 30-Jan-18 8:04am View    
If I read correctly you are trying to use the built-in functionality of DataTable to save changes. You might need to write your custom DataSource to acomplish this kind of task.
Bjørn 22-Apr-15 9:00am View    
When you add a click handler (the one automatically created when you double-click the Button in the designer) you can simply copy the "BackColor" property of the button:

private void button1_Click(object sender, EventArgs e)
{
Color c = button1.BackColor;
pictureBox1.Image = GetColoredBitmap(c, pictureBox1.Width, pictureBox1.Height);
pictureBox1.BackColor = c;
}

You should also set the "BackColor" property of the PictureBox like in the example above because getting the color of the Image is a bit more complicated.

If you're a bit more advanced, you can also assign the same click handler to all buttons like this:

private void ClickHandler(object sender, EventArgs e)
{
Color c = ((Control)sender).BackColor;
pictureBox1.Image = GetColoredBitmap(c, pictureBox1.Width, pictureBox1.Height);
pictureBox1.BackColor = c;
}

The sender is the Button which was clicked. I used a cast to a Control so not only Buttons but any Control types can be used.
Bjørn 22-Apr-15 7:35am View    
If you just mean making a PictureBox shoing the color, you can easily set the same property "BackColor":

pictureBox1.BackColor = Color.Red;

If you really want to use a picture (as in using a Bitmap) you'll have to create one manually:

public Bitmap GetColoredBitmap(Color c, int width, int height)
{
Bitmap bmp = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(c);
}
return bmp;
}

Then you can set the "Image" property of the PictureBox with that Bitmap. Use the PictureBox's "Width" and "Height" properties to make the Bitmap the same size as the PictureBox:

pictureBox1.Image = GetColoredBitmap(Color.Red, pictureBox1.Width, pictureBox1.Height);