📄 showbitmap.cs
字号:
// ShowBitmap.cs - Main form for ShowBitmap program, which
// demonstrates several ways to create and display bitmaps.
//
// Code from _Programming the .NET Compact Framework with C#_
// and _Programming the .NET Compact Framework with VB_
// (c) Copyright 2002-2004 Paul Yao and David Durant.
// All rights reserved.
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Reflection; // Needed for Assembly
using System.IO; // Needed for Stream
using System.Drawing.Imaging; // Needed for ImageAttributes
namespace ShowBitmap
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class FormMain : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu menuMain;
private System.Windows.Forms.MenuItem mitemFilePopup;
private System.Windows.Forms.MenuItem mitemFileOpen;
private System.Windows.Forms.MenuItem mitemResourcePopup;
private System.Windows.Forms.MenuItem mitemResourceCup;
private System.Windows.Forms.MenuItem mitemScalePopup;
private System.Windows.Forms.MenuItem mitemScale50;
private System.Windows.Forms.MenuItem mitemScale100;
private System.Windows.Forms.MenuItem mitemScale200;
private System.Windows.Forms.MenuItem mitemScale400;
private System.Windows.Forms.MenuItem mitemResourceBell;
private System.Windows.Forms.MenuItem mitemResourceClub;
private System.Windows.Forms.MenuItem mitemResourceDiamond;
private System.Windows.Forms.MenuItem mitemResourceHeart;
private System.Windows.Forms.MenuItem mitemResourceSpade;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.OpenFileDialog dlgFileOpen;
public FormMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
DisposeBitmap(ref bmpDraw);
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.menuMain = new System.Windows.Forms.MainMenu();
this.mitemFilePopup = new System.Windows.Forms.MenuItem();
this.mitemFileOpen = new System.Windows.Forms.MenuItem();
this.mitemResourcePopup = new System.Windows.Forms.MenuItem();
this.mitemResourceClub = new System.Windows.Forms.MenuItem();
this.mitemResourceDiamond = new System.Windows.Forms.MenuItem();
this.mitemResourceHeart = new System.Windows.Forms.MenuItem();
this.mitemResourceSpade = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.mitemResourceBell = new System.Windows.Forms.MenuItem();
this.mitemResourceCup = new System.Windows.Forms.MenuItem();
this.mitemScalePopup = new System.Windows.Forms.MenuItem();
this.mitemScale50 = new System.Windows.Forms.MenuItem();
this.mitemScale100 = new System.Windows.Forms.MenuItem();
this.mitemScale200 = new System.Windows.Forms.MenuItem();
this.mitemScale400 = new System.Windows.Forms.MenuItem();
this.dlgFileOpen = new System.Windows.Forms.OpenFileDialog();
//
// menuMain
//
this.menuMain.MenuItems.Add(this.mitemFilePopup);
this.menuMain.MenuItems.Add(this.mitemResourcePopup);
this.menuMain.MenuItems.Add(this.mitemScalePopup);
//
// mitemFilePopup
//
this.mitemFilePopup.MenuItems.Add(this.mitemFileOpen);
this.mitemFilePopup.Text = "File";
//
// mitemFileOpen
//
this.mitemFileOpen.Text = "Open...";
this.mitemFileOpen.Click += new System.EventHandler(this.mitemFileOpen_Click);
//
// mitemResourcePopup
//
this.mitemResourcePopup.MenuItems.Add(this.mitemResourceClub);
this.mitemResourcePopup.MenuItems.Add(this.mitemResourceDiamond);
this.mitemResourcePopup.MenuItems.Add(this.mitemResourceHeart);
this.mitemResourcePopup.MenuItems.Add(this.mitemResourceSpade);
this.mitemResourcePopup.MenuItems.Add(this.menuItem6);
this.mitemResourcePopup.MenuItems.Add(this.mitemResourceBell);
this.mitemResourcePopup.MenuItems.Add(this.mitemResourceCup);
this.mitemResourcePopup.Text = "Resource";
//
// mitemResourceClub
//
this.mitemResourceClub.Text = "Club";
this.mitemResourceClub.Click += new System.EventHandler(this.mitemResourceClub_Click);
//
// mitemResourceDiamond
//
this.mitemResourceDiamond.Text = "Diamond";
this.mitemResourceDiamond.Click += new System.EventHandler(this.mitemResourceDiamond_Click);
//
// mitemResourceHeart
//
this.mitemResourceHeart.Text = "Heart";
this.mitemResourceHeart.Click += new System.EventHandler(this.mitemResourceHeart_Click);
//
// mitemResourceSpade
//
this.mitemResourceSpade.Text = "Spade";
this.mitemResourceSpade.Click += new System.EventHandler(this.mitemResourceSpade_Click);
//
// menuItem6
//
this.menuItem6.Text = "-";
//
// mitemResourceBell
//
this.mitemResourceBell.Text = "Bell";
this.mitemResourceBell.Click += new System.EventHandler(this.mitemResourceBell_Click);
//
// mitemResourceCup
//
this.mitemResourceCup.Text = "Cup";
this.mitemResourceCup.Click += new System.EventHandler(this.mitemResourceCup_Click);
//
// mitemScalePopup
//
this.mitemScalePopup.MenuItems.Add(this.mitemScale50);
this.mitemScalePopup.MenuItems.Add(this.mitemScale100);
this.mitemScalePopup.MenuItems.Add(this.mitemScale200);
this.mitemScalePopup.MenuItems.Add(this.mitemScale400);
this.mitemScalePopup.Text = "Scale";
//
// mitemScale50
//
this.mitemScale50.Text = "50%";
this.mitemScale50.Click += new System.EventHandler(this.mitemScale_Click);
//
// mitemScale100
//
this.mitemScale100.Text = "100%";
this.mitemScale100.Click += new System.EventHandler(this.mitemScale_Click);
//
// mitemScale200
//
this.mitemScale200.Checked = true;
this.mitemScale200.Text = "200%";
this.mitemScale200.Click += new System.EventHandler(this.mitemScale_Click);
//
// mitemScale400
//
this.mitemScale400.Text = "400%";
this.mitemScale400.Click += new System.EventHandler(this.mitemScale_Click);
//
// FormMain
//
this.Menu = this.menuMain;
this.MinimizeBox = false;
this.Text = "Show Bitmap";
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.FormMain_MouseDown);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.FormMain_Paint);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new FormMain());
}
private Bitmap bmpDraw;
bool bFirstTime = true;
bool bResource = false;
string strResName;
// Draw a bitmap using transparency where the mouse
// down event is received.
private void
FormMain_MouseDown(object sender, MouseEventArgs e)
{
#if false
CreateAndDraw(e.X, e.Y);
#endif
// Get graphics object for form.
Graphics g = CreateGraphics();
// Create bitmap and graphics object for bitmap.
Bitmap bmpNew = new Bitmap(100,100);
Graphics gbmp = Graphics.FromImage(bmpNew);
// Clear bitmap background.
gbmp.Clear(Color.LightGray);
// Some drawing objects.
Pen penBlack = new Pen(Color.Black);
Brush brBlack = new SolidBrush(Color.Black);
Brush brYellow = new SolidBrush(Color.Yellow);
// Draw onto bitmap.
gbmp.FillEllipse(brYellow, 0, 0, 98, 98);
gbmp.DrawEllipse(penBlack, 0, 0, 98, 98);
gbmp.DrawString("At " + e.X.ToString() + "," + e.Y.ToString(), Font, brBlack, 40, 40);
// Copy bitmap to window at mouse down location.
if (bFirstTime)
{
// Copy without transparency.
g.DrawImage(bmpNew, e.X, e.Y);
bFirstTime = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -