Monday, December 06, 2004

I've updated the SIPControl to draw images in place of buttons. It required just minimal changes to the code. I added Image and ImageDown properties to the KeyButton class, and added an new override to the DrawButton method to support image drawing:

private void DrawButton(string text, Graphics gx, Rectangle rc, Color foreColor, Image image)

{

      Brush foreBrush = new SolidBrush(foreColor);

     

      // draw image

      gx.DrawImage(image, rc.Left, rc.Top);

      //Center the text

      SizeF size = gx.MeasureString(text, this.Font);

           

      int X = rc.Left + (int)(rc.Width - size.Width)/2;

      int Y = rc.Top + (int)(rc.Height - size.Height)/2;

                 

      gx.DrawString(text, this.Font, foreBrush, X, Y);

                 

      foreBrush.Dispose();

}

I've also modified the OnPaint method to recognize if the KeyButton has an image assigned. So now, if you'd want to have image to draw a button, the client code would look like that:

ButtonRow row1 = new ButtonRow(new string[]{"q","w","e","r","t","y","u","i","o","p","[","]"}, 5, 20);

row1.Space = 0;

//Assign images

foreach(KeyButton button in row1.Buttons)

{

      button.Image = bitmap;

      button.ImageDown = bitmapDown;

}

And here's the screen shot of the sample:

Download the new version of the SIPControl and a sample here.

SIPTest1.zip (10.05 KB)

12/6/2004 5:51:37 PM (GMT Standard Time, UTC+00:00)  #     |