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

📄 tipoftheday.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
//  TipOfTheDay.cs
//  Copyright (C) 2000 Mike Krueger
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Drawing;
using System.ComponentModel;
using System.Resources;
using System.Windows.Forms;
using System.Xml;
using System.IO;

using SharpDevelop.Gui;
using SharpDevelop.Tool.Data;
using SharpDevelop.Tool.Text;

namespace SharpDevelop.Gui.Dialogs {
    
	public class TipOfTheDayView : UserControl
	{
		readonly int ICON_DISTANCE = 16;
		Bitmap     icon      = null;
		Font     titlefont = new Font("Times new Roman", 15, FontStyle.Bold);
		Font     textfont  = new Font("Times new Roman", 12);
		string[] tips;
		int      curtip = 0;
		
		string didyouknowtext;
		
		public TipOfTheDayView(XmlElement el)
		{
			this.didyouknowtext = Resource.GetString("Dialog.TipOfTheDay.DidYouKnowText");
			
			icon   = Resource.GetBitmap("Icons.TipOfTheDayIcon");
			
			
//			XmlNodeList nodes = el.GetElementsByTagName("TIP");
			XmlNodeList nodes = el.ChildNodes;
			
			tips = new string[nodes.Count];
			for (int i = 0; i < nodes.Count; ++i) {
				tips[i] = StringParser.Parse(nodes[i].InnerText);
			}
			
			curtip = (new Random().Next()) % nodes.Count;
			
		}
		
		protected override void OnPaintBackground(PaintEventArgs pe)
		{}
		
		protected override void OnPaint(PaintEventArgs pe)
		{
			Graphics g = pe.Graphics;
			
			g.FillRectangle(new SolidBrush(Color.Gray), 0,
			                                            0,
			                                            icon.Width + ICON_DISTANCE,
			                                            Height);
			g.FillRectangle(new SolidBrush(Color.White), 0 + icon.Width + ICON_DISTANCE,
		                                                      	 0,
			                                                       Width - icon.Width - ICON_DISTANCE,
																   Height);
			g.DrawImage(icon, 2 + ICON_DISTANCE / 2, 4);
			
			g.DrawString(didyouknowtext, titlefont, new SolidBrush(Color.Black), icon.Width + ICON_DISTANCE + 4, 8);
			
			g.DrawLine(new Pen(Color.Black), new Point(icon.Width + ICON_DISTANCE, 8 + titlefont.Height + 2),
			                                 new Point(Width, 8 + titlefont.Height + 2));
			drawrect = new Rectangle(icon.Width + ICON_DISTANCE, 8 + titlefont.Height + 6,
									 Width - icon.Width - ICON_DISTANCE, Height - (8 + titlefont.Height + 6));
			
			g.DrawString(tips[curtip], textfont, new SolidBrush(Color.Black), drawrect);
		}
		Rectangle drawrect;
		
		public void NextTip()
		{
			curtip = (curtip + 1) % tips.Length;
			Invalidate(drawrect);
			Update();
		}
	}
	
    public class TipOfTheDayDialog : Form 
    {
	
		private System.ComponentModel.Container components;
		private CheckBox checkBox1;
		private Button button2;
		private Button button1;
		
		Panel panel = new Panel();
		TipOfTheDayView tipview;
		
		void NextTip(object sender, EventArgs e)
		{
			tipview.NextTip();
		}
		
		void CheckChange(object sender, EventArgs e)
		{
			Option.SetProperty("SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", checkBox1.Checked);
		}
		
		public TipOfTheDayDialog()
		{
			
			InitializeComponent();
			TopMost = true;
			StartPosition = FormStartPosition.CenterParent;
			
			Icon = null;
			
			XmlDocument doc = new XmlDocument();
			doc.Load(Application.StartupPath + "\\options\\TipsOfTheDay.xml" );
				
			tipview = new TipOfTheDayView(doc.DocumentElement);
			panel.Controls.Add(tipview);
//			panel.FormBorderStyle = FormBorderStyle.Fixed3D;
			Controls.Add(panel);
			
			panel.Width  = tipview.Width  = Width - 24;
			panel.Height = tipview.Height = button1.Top - 15;
			panel.Location = new Point(8, 5);
			button1.Click += new EventHandler(NextTip);
			
			checkBox1.CheckedChanged += new EventHandler(CheckChange);
			checkBox1.Checked = Boolean.Parse(Option.GetProperty("SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", true).ToString());
			
			MaximizeBox  = MinimizeBox = false;
			ShowInTaskbar = false;
			
		}
		
		public override void Dispose()
        {
            base.Dispose();
            components.Dispose();
        }
        
        private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.button2 = new Button();
			this.checkBox1 = new CheckBox();
			this.button1 = new Button();
			
			button2.Location = new System.Drawing.Point(328, 232);
			button2.DialogResult = DialogResult.Cancel;
			button2.Size = new System.Drawing.Size(80, 24);
			button2.TabIndex = 1;
			button2.Text = Resource.GetString("Global.CloseButtonText");
			
			checkBox1.Location = new System.Drawing.Point(8, 232);
			checkBox1.Text = Resource.GetString("Dialog.TipOfTheDay.checkBox1Text");
			checkBox1.Size = new System.Drawing.Size(136, 24);
//			checkBox1.AccessibleRole = AccessibleRoles.CheckButton;
			checkBox1.TabIndex = 2;
			checkBox1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.Text = Resource.GetString("Dialog.TipOfTheDay.DialogName");
			//@design this.TrayLargeIcon = true;
			this.FormBorderStyle = FormBorderStyle.FixedDialog;
			//@design this.TrayHeight = 0;
			this.ClientSize = new System.Drawing.Size(418, 263);
			
			button1.Location = new System.Drawing.Point(240 - 16, 232);
			button1.Size = new System.Drawing.Size(96, 24);
			button1.TabIndex = 0;
			button1.Text = Resource.GetString("Dialog.TipOfTheDay.button1Text");
			
			this.Controls.Add(checkBox1);
			this.Controls.Add(button2);
			this.Controls.Add(button1);
		}
    }
}

⌨️ 快捷键说明

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