Hello,

i want to ask if image buttons are supported by Smart Device Applications?

thx

regards

pat

Re: image buttons by Peter

Peter
Thu Sep 30 07:05:01 CDT 2004

Not directly, but it is fairly straight-forward to implement:-
http://samples.gotdotnet.com/quickstart/CompactFramework/doc/picturebutton.aspx

Or you can use the ready-made ButtonEx in the Smart Device Framework
(www.opennetcf.org/sdf/)

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org

Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups? Let us know!
https://www.windowsembeddedeval.com/community/newsgroups

"pat" <pat@discussions.microsoft.com> wrote in message
news:F0C15676-44A1-4098-911E-EB9F95713C38@microsoft.com...
> Hello,
>
> i want to ask if image buttons are supported by Smart Device Applications?
>
> thx
>
> regards
>
> pat



Re: image buttons by pat

pat
Thu Sep 30 10:43:09 CDT 2004



Sorry but this code sample is in VB and i have no experiences in VB :( Is
such an code sample also available in C#??:-/

regards

patrick

Re: image buttons by DarrenShaffer

DarrenShaffer
Thu Sep 30 18:43:03 CDT 2004

Here you go Pat:

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;

namespace Sample
{
public class ImageButton : Control
{
private Image image;
private bool bPushed;
private Bitmap m_bmpOffscreen;

public Image Image
{
get { return image; }
set { image = value; }
}

public ImageButton()
{
bPushed = false;
this.Size = new Size(21, 21);
}

protected override void OnPaint(System.Windows.Forms.PaintEventArgs e )
{
Graphics gxOff;
Rectangle imgRect;
Brush backBrush;
if (m_bmpOffscreen == null)
m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
gxOff = Graphics.FromImage(m_bmpOffscreen);
gxOff.Clear(this.BackColor);

if (!bPushed)
backBrush = new SolidBrush(Parent.BackColor);
else
backBrush = new SolidBrush(Color.LightGray);

gxOff.FillRectangle(backBrush, this.ClientRectangle);

if (image != null)
{
int imageLeft = (this.Width - image.Width) / 2;
int imageTop = (this.Height - image.Height) / 2;

if (!bPushed)
imgRect = new Rectangle(imageLeft, imageTop, image.Width, image.Height);
else
imgRect = new Rectangle(imageLeft + 1 , imageTop +1, image.Width,
image.Height);

ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorKey(BackgroundImageColor(image),
BackgroundImageColor(image));
gxOff.DrawImage(image, imgRect, 0, 0, image.Width, image.Height,
GraphicsUnit.Pixel, imageAttr);
}
if (bPushed)
{
Rectangle rc = this.ClientRectangle;
rc.Width--;
rc.Height--;
gxOff.DrawRectangle(new Pen(Color.Black), rc);
}
e.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
base.OnPaint(e);
}

protected override void
OnPaintBackground(System.Windows.Forms.PaintEventArgs e )
{
}

protected override void OnMouseDown ( System.Windows.Forms.MouseEventArgs e )
{
bPushed = true;
this.Invalidate();
}

protected override void OnMouseUp ( System.Windows.Forms.MouseEventArgs e )
{
bPushed = false;
this.Invalidate();
}

private Color BackgroundImageColor(Image image)
{
Bitmap bmp = new Bitmap(image);
return bmp.GetPixel(0, 0);
}
}
}

- Darren Shaffer



"pat" wrote:

>
>
> Sorry but this code sample is in VB and i have no experiences in VB :( Is
> such an code sample also available in C#??:-/
>
> regards
>
> patrick

Re: image buttons by pat

pat
Fri Oct 01 03:05:03 CDT 2004

Dear Mr. Shaffer!

Thank you for your detailed reply!! Do i then only have to write something
like this?

ImageButton button = new ImageButton();

But where can i indicate where the button should be situated on the Form of
the Smart Device Application and which image - the source - should contain
the button?

regards

patrick

"Darren Shaffer" wrote:

> Here you go Pat:
>
> using System;
> using System.Drawing;
> using System.Windows.Forms;
> using System.Drawing.Imaging;
>
> namespace Sample
> {
> public class ImageButton : Control
> {
> private Image image;
> private bool bPushed;
> private Bitmap m_bmpOffscreen;
>
> public Image Image
> {
> get { return image; }
> set { image = value; }
> }
>
> public ImageButton()
> {
> bPushed = false;
> this.Size = new Size(21, 21);
> }
>
> protected override void OnPaint(System.Windows.Forms.PaintEventArgs e )
> {
> Graphics gxOff;
> Rectangle imgRect;
> Brush backBrush;
> if (m_bmpOffscreen == null)
> m_bmpOffscreen = new Bitmap(ClientSize.Width, ClientSize.Height);
> gxOff = Graphics.FromImage(m_bmpOffscreen);
> gxOff.Clear(this.BackColor);
>
> if (!bPushed)
> backBrush = new SolidBrush(Parent.BackColor);
> else
> backBrush = new SolidBrush(Color.LightGray);
>
> gxOff.FillRectangle(backBrush, this.ClientRectangle);
>
> if (image != null)
> {
> int imageLeft = (this.Width - image.Width) / 2;
> int imageTop = (this.Height - image.Height) / 2;
>
> if (!bPushed)
> imgRect = new Rectangle(imageLeft, imageTop, image.Width, image.Height);
> else
> imgRect = new Rectangle(imageLeft + 1 , imageTop +1, image.Width,
> image.Height);
>
> ImageAttributes imageAttr = new ImageAttributes();
> imageAttr.SetColorKey(BackgroundImageColor(image),
> BackgroundImageColor(image));
> gxOff.DrawImage(image, imgRect, 0, 0, image.Width, image.Height,
> GraphicsUnit.Pixel, imageAttr);
> }
> if (bPushed)
> {
> Rectangle rc = this.ClientRectangle;
> rc.Width--;
> rc.Height--;
> gxOff.DrawRectangle(new Pen(Color.Black), rc);
> }
> e.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
> base.OnPaint(e);
> }
>
> protected override void
> OnPaintBackground(System.Windows.Forms.PaintEventArgs e )
> {
> }
>
> protected override void OnMouseDown ( System.Windows.Forms.MouseEventArgs e )
> {
> bPushed = true;
> this.Invalidate();
> }
>
> protected override void OnMouseUp ( System.Windows.Forms.MouseEventArgs e )
> {
> bPushed = false;
> this.Invalidate();
> }
>
> private Color BackgroundImageColor(Image image)
> {
> Bitmap bmp = new Bitmap(image);
> return bmp.GetPixel(0, 0);
> }
> }
> }
>
> - Darren Shaffer
>
>
>
> "pat" wrote:
>
> >
> >
> > Sorry but this code sample is in VB and i have no experiences in VB :( Is
> > such an code sample also available in C#??:-/
> >
> > regards
> >
> > patrick

Re: image buttons by Chris

Chris
Fri Oct 01 08:49:24 CDT 2004

It seems like you're trying to run before you've learned to crawl. At this
point you really need to get a "Beginning C# Programming book" and read
through it. Control placement is about as simple a concept as there is, and
setting an image is fairly evident by just reading the code provided. Wrox
press does a good introduction to C# book, though I'm sure most publishers
do.

Once you've gone through a bsaic tutorial and understand the code Darren
posted, then you can begin to do more involved work.

As for Darren'c code specifically, I'd avoid all the object creation in
OnPaint - it's called a lot and this is a perf hit. Also, thing like Brush
objects should be disposed when you're done with them. Again, once you get
through some of the basics, these comments will make more sense.

-Chris




"pat" <pat@discussions.microsoft.com> wrote in message
news:5847D1BA-5159-49E2-9857-F848E288AC84@microsoft.com...
> Dear Mr. Shaffer!
>
> Thank you for your detailed reply!! Do i then only have to write something
> like this?
>
> ImageButton button = new ImageButton();
>
> But where can i indicate where the button should be situated on the Form
of
> the Smart Device Application and which image - the source - should
contain
> the button?
>
> regards
>
> patrick
>
> "Darren Shaffer" wrote:
>
> > Here you go Pat:
> >
> > using System;
> > using System.Drawing;
> > using System.Windows.Forms;
> > using System.Drawing.Imaging;
> >
> > namespace Sample
> > {
> > public class ImageButton : Control
> > {
> > private Image image;
> > private bool bPushed;
> > private Bitmap m_bmpOffscreen;
> >
> > public Image Image
> > {
> > get { return image; }
> > set { image = value; }
> > }
> >
> > public ImageButton()
> > {
> > bPushed = false;
> > this.Size = new Size(21, 21);
> > }
> >
> > protected override void
OnPaint(System.Windows.Forms.PaintEventArgs e )
> > {
> > Graphics gxOff;
> > Rectangle imgRect;
> > Brush backBrush;
> > if (m_bmpOffscreen == null)
> > m_bmpOffscreen = new Bitmap(ClientSize.Width,
ClientSize.Height);
> > gxOff = Graphics.FromImage(m_bmpOffscreen);
> > gxOff.Clear(this.BackColor);
> >
> > if (!bPushed)
> > backBrush = new SolidBrush(Parent.BackColor);
> > else
> > backBrush = new SolidBrush(Color.LightGray);
> >
> > gxOff.FillRectangle(backBrush, this.ClientRectangle);
> >
> > if (image != null)
> > {
> > int imageLeft = (this.Width - image.Width) / 2;
> > int imageTop = (this.Height - image.Height) / 2;
> >
> > if (!bPushed)
> > imgRect = new Rectangle(imageLeft, imageTop, image.Width, image.Height);
> > else
> > imgRect = new Rectangle(imageLeft + 1 , imageTop +1, image.Width,
> > image.Height);
> >
> > ImageAttributes imageAttr = new ImageAttributes();
> > imageAttr.SetColorKey(BackgroundImageColor(image),
> > BackgroundImageColor(image));
> > gxOff.DrawImage(image, imgRect, 0, 0, image.Width, image.Height,
> > GraphicsUnit.Pixel, imageAttr);
> > }
> > if (bPushed)
> > {
> > Rectangle rc = this.ClientRectangle;
> > rc.Width--;
> > rc.Height--;
> > gxOff.DrawRectangle(new Pen(Color.Black), rc);
> > }
> > e.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
> > base.OnPaint(e);
> > }
> >
> > protected override void
> > OnPaintBackground(System.Windows.Forms.PaintEventArgs e )
> > {
> > }
> >
> > protected override void OnMouseDown (
System.Windows.Forms.MouseEventArgs e )
> > {
> > bPushed = true;
> > this.Invalidate();
> > }
> >
> > protected override void OnMouseUp ( System.Windows.Forms.MouseEventArgs
e )
> > {
> > bPushed = false;
> > this.Invalidate();
> > }
> >
> > private Color BackgroundImageColor(Image image)
> > {
> > Bitmap bmp = new Bitmap(image);
> > return bmp.GetPixel(0, 0);
> > }
> > }
> > }
> >
> > - Darren Shaffer
> >
> >
> >
> > "pat" wrote:
> >
> > >
> > >
> > > Sorry but this code sample is in VB and i have no experiences in VB
:( Is
> > > such an code sample also available in C#??:-/
> > >
> > > regards
> > >
> > > patrick



Re: image buttons by pat

pat
Sat Oct 02 03:03:08 CDT 2004


I already programmed with C#, especially WebServices and already read a
introduction book to c# also to the .net compact framework. though i do not
know how to use the code of Darren Shaffer in a specific example..:((???

regards

patrick

Re: image buttons by Darren

Darren
Mon Oct 04 16:54:32 CDT 2004

Pat,

Start by declaring your ImageButton in the form class that will contain the
button:

private ImageButton btnMyImageButton;

// then, initialize it right after the Forms Designer generated code:
btnMyImageButton = new ImageButton();
btnMyImageButton.Image = new
Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("someImage.bmp"));
btnMyImageButton.Location = new Point(16, 200);
btnMyImageButton.Size = new Size(16, 16);

// now add an event handler for the click event
btnMyImageButton.Click+=new EventHandler(btnPanUp_Click);

// add the ImageButton to the controls collection of your form (you can also
add it to a panel, picturebox, etc)
this.Controls.Add(btnMyImageButton);

// if it gets hidden behind something else in the Z-order, simply:
btnMyImageButton.BringToFront();

//finally, add the event handler:
private void btnMyImageButton_Click(object sender, EventArgs e)
{
// do something
}

-Darren




"pat" <pat@discussions.microsoft.com> wrote in message
news:19089767-EAA5-457B-B15F-204744164EFC@microsoft.com...
>
> I already programmed with C#, especially WebServices and already read a
> introduction book to c# also to the .net compact framework. though i do
> not
> know how to use the code of Darren Shaffer in a specific example..:((???
>
> regards
>
> patrick