本文整理汇总了C#中System.Windows.Forms.Cursor.Draw方法的典型用法代码示例。如果您正苦于以下问题:C# Cursor.Draw方法的具体用法?C# Cursor.Draw怎么用?C# Cursor.Draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Cursor
的用法示例。
在下文中一共展示了Cursor.Draw方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateRealHeight
private static int CalculateRealHeight(Cursor cursor)
{
using (Bitmap bitmap = new Bitmap(cursor.Size.Width, cursor.Size.Height))
{
Rectangle targetRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
cursor.Draw(graphics, targetRect);
}
BitmapData bitmapdata = bitmap.LockBits(targetRect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
try
{
if (bitmapdata.PixelFormat == PixelFormat.Format32bppArgb)
{
int height = bitmapdata.Height;
do
{
int num2 = --height * bitmapdata.Stride;
for (int i = 0; i < bitmapdata.Width; i++)
{
if ((Marshal.ReadInt32(bitmapdata.Scan0, num2 + (i * 4)) != 0) && (height > 0))
{
return height;
}
}
}
while (height > 0);
}
}
finally
{
bitmap.UnlockBits(bitmapdata);
}
}
return cursor.Size.Height;
}
示例2: GetScreen
private Bitmap GetScreen()
{
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
if (this.isCaptureCursor)
{
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{
CCWin.Win32.NativeMethods.PCURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CCWin.Win32.NativeMethods.PCURSORINFO));
CCWin.Win32.NativeMethods.GetCursorInfo(out pci);
if (pci.hCursor != IntPtr.Zero)
{
Cursor cur = new Cursor(pci.hCursor);
g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
cur.Draw(g, new Rectangle((System.Drawing.Point) (((System.Drawing.Size) Control.MousePosition) - ((System.Drawing.Size) cur.HotSpot)), cur.Size));
}
}
}
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
}
return bmp;
}
示例3: ConvertToBitmap
public Bitmap ConvertToBitmap(Cursor c)
{
//it seems there is no easy way to write cursor to file
Bitmap bmp = new Bitmap(c.Size.Width, c.Size.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
c.Draw(g, new Rectangle(0, 0, c.Size.Width, c.Size.Height));
}
return bmp;
}
示例4: function_ScreenProjecting
private void function_ScreenProjecting()
{
Bitmap Bm_temp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics g_temp = Graphics.FromImage(Bm_temp);
MemoryStream MS_temp = new MemoryStream();
g_temp.CopyFromScreen(0, 0, 0, 0, Bm_temp.Size);
CURSORINFO CRS;
CRS.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out CRS);
Cursor cur = new Cursor(CRS.hCursor);
//MessageBox.Show(this, cur.Size.ToString());
cur.Draw(g_temp, new Rectangle(CRS.ptScreenPos.X - (Cursors.Arrow.Size.Width - cur.Size.Width), CRS.ptScreenPos.Y - (Cursors.Arrow.Size.Height - cur.Size.Height), cur.Size.Width, cur.Size.Height));
Bm_temp.Save(MS_temp, System.Drawing.Imaging.ImageFormat.Jpeg);
//Bm_temp.Save("111.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
Byte[] byte_temp = MS_temp.GetBuffer();
//MessageBox.Show(byte_temp.Length.ToString(), "");
try
{
this.SocketClient.BeginSend(byte_temp, 0, byte_temp.Length, SocketFlags.None, new AsyncCallback(CallBack_Send), this.SocketClient);
}
catch (Exception E)
{
MessageBox.Show(E.ToString());
this.SocketConnetingProcessStatusLabel.Text = "开始发送Socket消息时,错误!";
}
MS_temp.Close();
g_temp.Dispose();
Bm_temp.Dispose();
}
示例5: GetScreen
//获取桌面图像
private Bitmap GetScreen()
{
Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
if (this.isCaptureCursor)
{ //是否捕获鼠标
//如果直接将捕获当的鼠标画在bmp上 光标不会反色 指针边框也很浓 也就是说
//尽管bmp上绘制了图像 绘制鼠标的时候还是以黑色作为鼠标的背景 然后在将混合好的鼠标绘制到图像 会很别扭
//所以 干脆直接在桌面把鼠标绘制出来再截取桌面
using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
{ //传入0默认就是桌面 Win32.GetDesktopWindow()也可以
Win32.PCURSORINFO pci;
pci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Win32.PCURSORINFO));
Win32.GetCursorInfo(out pci);
if (pci.hCursor != IntPtr.Zero)
{
Cursor cur = new Cursor(pci.hCursor);
g.CopyFromScreen(0, 0, 0, 0, bmp.Size); //在桌面绘制鼠标前 先在桌面绘制一下当前的桌面图像
//如果不绘制当前桌面 那么cur.Draw的时候会是用历史桌面的快照 进行鼠标的混合 那么到时候混出现底色(测试中就是这样的)
cur.Draw(g, new Rectangle((Point)((Size)MousePosition - (Size)cur.HotSpot), cur.Size));
}
}
}
//做完以上操作 才开始捕获桌面图像
using (Graphics g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(0, 0, 0, 0, bmp.Size);
}
return bmp;
}
示例6: CaptureScreenToBitmap
private void CaptureScreenToBitmap(Bitmap bitmap)
{
try
{
using (Graphics graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(0, 0, 0, 0, new Size(screenWidth, screenHeight),
CopyPixelOperation.SourceCopy);
CURSORINFO cursorInfo = new CURSORINFO();
cursorInfo.cbSize = Marshal.SizeOf(cursorInfo);
if (GetCursorInfo(ref cursorInfo))
{
if (cursorInfo.flags == CURSOR_SHOWING)
{
Cursor cursor = new Cursor(cursorInfo.hCursor);
cursor.Draw(graphics, new Rectangle(
cursorInfo.ptScreenPos.x - cursor.HotSpot.X,
cursorInfo.ptScreenPos.y - cursor.HotSpot.Y,
cursor.Size.Width, cursor.Size.Height));
}
}
}
}
catch (Exception ex)
{
throw new ScreenshotNotAvailableException("Could not capture screenshot. The application may be running as a service that has not been granted the right to interact with the desktop.", ex);
}
}
示例7: DrawCross
static void DrawCross(Graphics g, Point center)
{
System.IO.MemoryStream ms = null;
try
{
ms = new System.IO.MemoryStream(Properties.Resources.Cross);
using (Cursor cursor = new Cursor(ms))
{
ms = null;
cursor.Draw(g, new Rectangle(center.X - 15, center.Y - 15, 32, 32));
}
}
finally
{
if (ms != null)
ms.Dispose();
}
}
示例8: drawMouse
public void drawMouse(Point Location, Cursor MouseCursor)
{
this.Invalidate();
ClearMouse(Location, MouseCursor);
Graphics MouseGraphics = CreateGraphics();
Rectangle MouseRectangle = new Rectangle(Location, MouseCursor.Size);
MouseCursor.Draw(MouseGraphics, MouseRectangle);
}
示例9: UpdateState
private void UpdateState()
{
var imagePath = this.fileNameComboBox.Text;
if (this.lastLoadedPath == imagePath)
{
return;
}
this.lastLoadedPath = imagePath;
this.pictureBox1.SuspendLayout();
try
{
this.okButton.Enabled = imagePath.Length == 0 || this.editor.Filter.IsSupported(imagePath);
if (this.okButton.Enabled)
{
if (ImageEditor.IsCursorFile(imagePath))
{
using (Cursor cursor = new Cursor(imagePath))
{
this.pictureBox1.Image = new Bitmap(cursor.Size.Width, cursor.Size.Height);
using (Graphics g = Graphics.FromImage(this.pictureBox1.Image))
{
cursor.Draw(g, new Rectangle(Point.Empty, cursor.Size));
}
}
}
else if (ImageEditor.IsIconFile(imagePath))
{
using (Icon icon = new Icon(imagePath))
{
this.pictureBox1.Image = icon.ToBitmap();
}
}
else if (imagePath.Length == 0)
{
this.pictureBox1.Image = null;
}
else
{
this.pictureBox1.Image = Image.FromFile(imagePath);
}
}
else
{
this.pictureBox1.Image = this.pictureBox1.ErrorImage;
}
}
catch (Exception ex)
{
if (Microsoft.VisualStudio.ErrorHandler.IsCriticalException(ex))
{
throw;
}
this.okButton.Enabled = false;
this.pictureBox1.Image = this.pictureBox1.ErrorImage;
}
this.pictureBox1.ResumeLayout();
}
示例10: DisplayAsset
private void DisplayAsset()
{
PictureBox picBox = null;
switch (_type)
{
case EngineResourceFileTypes.Bitmap:
btnBackground.Visible = true;
btnMask.Visible = true;
axWMP.Visible = false;
picBox = new PictureBox();
picBox.SizeMode = PictureBoxSizeMode.AutoSize;
picBox.Image = new Bitmap(_stream);
picBox.MouseClick += picBox_MouseClick;
this.panel1.Controls.Add(picBox);
break;
case EngineResourceFileTypes.Audio:
case EngineResourceFileTypes.Video:
btnBackground.Visible = false;
btnMask.Visible = false;
panel1.Dock = DockStyle.Fill;
if (!string.IsNullOrWhiteSpace(_file))
{
axWMP.settings.autoStart = false;
axWMP.Visible = true;
axWMP.URL = _file;
axWMP.Dock = DockStyle.Fill;
}
break;
case EngineResourceFileTypes.Cursor:
btnBackground.Visible = false;
btnMask.Visible = false;
axWMP.Visible = false;
picBox = new PictureBox();
picBox.SizeMode = PictureBoxSizeMode.AutoSize;
picBox.BorderStyle = BorderStyle.Fixed3D;
var cursor = new Cursor(_file);
var bmp = new Bitmap(cursor.Size.Width, cursor.Size.Height);
using (var graphics = Graphics.FromImage(bmp))
cursor.Draw(graphics, new Rectangle(new Point(), cursor.Size));
picBox.Image = bmp;
picBox.MouseClick += picBox_MouseClick;
this.panel1.Controls.Add(picBox);
break;
case EngineResourceFileTypes.Misc:
btnBackground.Text = "Open File";
btnBackground.Visible = true;
btnMask.Visible = false;
axWMP.Visible = false;
break;
default:
btnBackground.Visible = false;
btnMask.Visible = false;
axWMP.Visible = false;
break;
}
}