نوشته شده توسط
mehdiizadi
سلام دوستان.
میخواستم بپرسم چطوری میشه یک عکس رو توی messagebox قرار داد ؟
ممنون میشم کمکم کنید.
یا حق
با سلام
با استفاده از تابع FindWindowA از User32.dll، هندل پنجره MessageBox را به دست بیاورید، سپس با استباده از Graphics.FromHwnd یک Graphics ساخته و تصویر را رسم کنید. به این صورت:
//in the name of god
//صل الله علی محمد و آله
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public class MessageBox
{
[DllImport("user32", EntryPoint = "FindWindowA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32", EntryPoint = "GetWindowRect", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int GetWindowRect(IntPtr hwnd, ref rect lpRect);
public struct rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public static void Show(string title, string text, string ImageFileName)
{
System.Threading.Thread NewThread = new System.Threading.Thread(new System.Threading.ThreadStart(() => System.Windows.Forms.MessageBox.Show(text, title)));
NewThread.Start();
NewThread.Priority = System.Threading.ThreadPriority.Highest;
System.Threading.Thread.Sleep(50);
System.Media.SystemSounds.Hand.Play();
IntPtr MessageBoxHandle = FindWindow(null, title);
rect messageBoxRect = default(rect);
GetWindowRect(MessageBoxHandle, ref messageBoxRect);
using (System.Drawing.Graphics MessageBoxGraphic = System.Drawing.Graphics.FromHwnd(MessageBoxHandle) )
{
MessageBoxGraphic.DrawImage(Image.FromFile(ImageFi leName), 0, 0, messageBoxRect.Right - messageBoxRect.Left, messageBoxRect.Bottom - messageBoxRect.Top);
}
}
}
}
موفق باشید.