⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MobileDevelopersHandbook
{
    public partial class Form1 : Form
    {
        private Bitmap offscreenBuffer = null;
        
        public Form1()
        {
            InitializeComponent();
        }

        private void closeMenuItem_Click(object sender, EventArgs e)
        {
            Settings.SaveSettings();
            this.Close();
        }

        private void settingsMenuItem_Click(object sender, EventArgs e)
        {
            SettingsForm form = new SettingsForm();
            form.ShowDialog();
            RepaintTextArea();
        }

        private void Form1_Closing(object sender, CancelEventArgs e)
        {
            offscreenBuffer.Dispose();
            offscreenBuffer = null;
        }

        private void RepaintTextArea()
        {
            UpdateOffscreenBuffer();
            this.panel1.Invalidate();
        }

        private void UpdateOffscreenBuffer()
        {
            // Graphics settings
            Color backgroundColor = Settings.Instance.BackgroundColor;
            Color textColour = Settings.Instance.TextColor;
            float fontSize = (float)Settings.Instance.FontSize;
            string fontName = Settings.Instance.Fontname;

            if (offscreenBuffer == null)
                offscreenBuffer = new Bitmap(this.panel1.Width, this.panel1.Height);

            // Update the offscreen buffer.
            using (Graphics memDC = Graphics.FromImage(offscreenBuffer))
            {
                memDC.Clear(backgroundColor);
                using (Font boldFont = new Font(fontName, fontSize, FontStyle.Bold))
                {
                    using (Brush brsh = new SolidBrush(textColour))
                    {

                        memDC.DrawString("The style of this text", boldFont, brsh, 5, 5);
                        memDC.DrawString("is saved in Settings", boldFont, brsh, 5, 20);
                    }
                }
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            RepaintTextArea();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            if (offscreenBuffer == null)
                UpdateOffscreenBuffer();
            // Draw from background buffer to Panel
            e.Graphics.DrawImage(offscreenBuffer, 0, 0);

        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -