0
私はWindows Mobileで自分のアプリケーションの画像ボタンを作成しました。しかし、小さな問題があります。たとえば、画面の解像度が異なると、画像がコントロールに収まるように自動的にサイズが変更されません。これはどうすればできますか?画像ボタンCF.net
ありがとうございます。
これはあなたがのOnPaintなどの際に、画像を拡大縮小する必要があるのOnPaint機能のための私のコード
Dim gxOff As Graphics
'Offscreen graphics
Dim imgRect As Rectangle
'image rectangle
Dim backBrush As Brush
'brush for filling a backcolor
If m_bmpOffscreen Is Nothing Then
'Bitmap for doublebuffering
m_bmpOffscreen = New Bitmap(Me.Width, Me.Height)
End If
gxOff = Graphics.FromImage(m_bmpOffscreen)
gxOff.Clear(Me.BackColor)
If Not bPushed Then
backBrush = New SolidBrush(Parent.BackColor)
Else
backBrush = New SolidBrush(Color.Black)
'change the background when it's pressed
End If
gxOff.FillRectangle(backBrush, Me.ClientRectangle)
If m_image IsNot Nothing Then
'Center the image relativelly to the control
Dim imageLeft As Integer = (Me.Width - m_image.Width)/2
Dim imageTop As Integer = (Me.Height - m_image.Height)/2
If Not bPushed Then
imgRect = New Rectangle(imageLeft, imageTop, m_image.Width, m_image.Height)
Else
'The button was pressed
'Shift the image by one pixel
imgRect = New Rectangle(imageLeft + 1, imageTop + 1, m_image.Width, m_image.Height)
End If
'Set transparent key
Dim imageAttr As New Imaging.ImageAttributes()
imageAttr.SetColorKey(BackgroundImageColor(m_image), BackgroundImageColor(m_image))
'Draw image
gxOff.DrawImage(m_image, imgRect, 0, 0, m_image.Width, m_image.Height, GraphicsUnit.Pixel, imageAttr)
End If
If bPushed Then
'The button was pressed
'Prepare rectangle
Dim rc As Rectangle = Me.ClientRectangle
rc.Width -= 1
rc.Height -= 1
'Draw rectangle
gxOff.DrawRectangle(New Pen(Color.Black), rc)
End If
'Draw from the memory bitmap
e.Graphics.DrawImage(m_bmpOffscreen, 0, 0)
MyBase.OnPaint(e)
私は上記のコードを入れてみましたが、didntの仕事をしました。 –
あなたのコードを修正する必要があります。あなたは例を入れなかったので、私は例を挙げました。基本的なアイデアは - あなたのイメージを手作業で拡大縮小する必要があります。上記の例では、qvgaとvgaのみをサポートしています。イメージはqvga用で、vgaデバイス上でスケールアップされます。 – Marcin