- PR -

MessageBoxIconをImageとしてFormに表示できますか?

1
投稿者投稿内容
nds053
会議室デビュー日: 2003/04/22
投稿数: 10
投稿日時: 2003-04-22 19:32
FormへPictureBoxなどを配置し、そこへ標準のMessageBoxのMessageBoxIconを表示
することは可能でしょうか?
わかる方がいらっしゃいましたら、よろしくお願い致します。
mei
大ベテラン
会議室デビュー日: 2003/04/08
投稿数: 114
投稿日時: 2003-04-22 20:09
こんな感じでしょうか?

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

public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.PictureBox pictureBox1;
private System.ComponentModel.Container components = null;

public Form1() {
InitializeComponent();

Bitmap bmp = new Bitmap(288, 32);
Graphics g = Graphics.FromImage(bmp);
g.DrawIcon(SystemIcons.Asterisk, 0, 0);
g.DrawIcon(SystemIcons.Error, 32, 0);
g.DrawIcon(SystemIcons.Exclamation, 64, 0);
g.DrawIcon(SystemIcons.Hand, 96, 0);
g.DrawIcon(SystemIcons.Information, 128, 0);
g.DrawIcon(SystemIcons.Question, 160, 0);
g.DrawIcon(SystemIcons.Warning, 192, 0);
g.DrawIcon(SystemIcons.WinLogo, 224, 0);
g.DrawIcon(SystemIcons.Application, 256, 0);
g.Dispose();
pictureBox1.Image = bmp;
}
protected override void Dispose( bool disposing ) {
if( disposing ) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent() {
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
this.pictureBox1.Location = new System.Drawing.Point(8, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(288, 32);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(296, 45);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.pictureBox1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
}
nds053
会議室デビュー日: 2003/04/22
投稿数: 10
投稿日時: 2003-04-23 09:19
申訳ありません、C#の知識がないのでわかりません…
できればVB.NETでの方法を教えていただけないでしょうか?
最初にこのことをお伝えするべきでした。ごめんなさい。
mei
大ベテラン
会議室デビュー日: 2003/04/08
投稿数: 114
投稿日時: 2003-04-23 12:29
ほとんど、変わらないと思いますが・・・

Public Class Form1
Inherits System.Windows.Forms.Form

Public Sub New()
MyBase.New()

InitializeComponent()

Dim bmp As New Bitmap(288, 32)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawIcon(SystemIcons.Asterisk, 0, 0)
g.DrawIcon(SystemIcons.Error, 32, 0)
g.DrawIcon(SystemIcons.Exclamation, 64, 0)
g.DrawIcon(SystemIcons.Hand, 96, 0)
g.DrawIcon(SystemIcons.Information, 128, 0)
g.DrawIcon(SystemIcons.Question, 160, 0)
g.DrawIcon(SystemIcons.Warning, 192, 0)
g.DrawIcon(SystemIcons.WinLogo, 224, 0)
g.DrawIcon(SystemIcons.Application, 256, 0)
g.Dispose()
PictureBox1.Image = bmp

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Private components As System.ComponentModel.IContainer

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.SuspendLayout()

Me.PictureBox1.Location = New System.Drawing.Point(8, 8)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(288, 32)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
Me.ClientSize = New System.Drawing.Size(296, 45)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.PictureBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub
End Class
nds053
会議室デビュー日: 2003/04/22
投稿数: 10
投稿日時: 2003-04-24 08:53
おかげさまでMessageBoxIconの表示ができました。
たしかにソースコードはあまりかわらないですね、C#のコードとみて
ちょっと引いてしまいました。これからはC#の方も少し学んでみよう
かと思います。どうもありがとうございました。
1

スキルアップ/キャリアアップ(JOB@IT)