| 0: | // TipOfTheDay.cs | |
| 1: | // Copyright (C) 2000 Mike Krueger | |
| 2: | // | |
| 3: | // This program is free software; you can redistribute it and/or modify | |
| 4: | // it under the terms of the GNU General Public License as published by | |
| 5: | // the Free Software Foundation; either version 2 of the License, or | |
| 6: | // (at your option) any later version. | |
| 7: | // | |
| 8: | // This program is distributed in the hope that it will be useful, | |
| 9: | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10: | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 11: | // GNU General Public License for more details. | |
| 12: | // | |
| 13: | // You should have received a copy of the GNU General Public License | |
| 14: | // along with this program; if not, write to the Free Software | |
| 15: | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 16: | ||
| 17: | using System; | |
| 18: | using System.Drawing; | |
| 19: | using System.ComponentModel; | |
| 20: | using System.Resources; | |
| 21: | using System.Windows.Forms; | |
| 22: | using System.Xml; | |
| 23: | using System.IO; | |
| 24: | ||
| 25: | using SharpDevelop.Gui; | |
| 26: | using SharpDevelop.Tool.Data; | |
| 27: | using SharpDevelop.Tool.Text; | |
| 28: | ||
| 29: | namespace SharpDevelop.Gui.Dialogs { | |
| 30: | ||
| 31: | public class TipOfTheDayView : UserControl | |
| 32: | { | |
| 33: | readonly int ICON_DISTANCE = 16; | |
| 34: | Bitmap icon = null; | |
| 35: | Font titlefont = new Font("Times new Roman", 15, FontStyle.Bold); | |
| 36: | Font textfont = new Font("Times new Roman", 12); | |
| 37: | string[] tips; | |
| 38: | int curtip = 0; | |
| 39: | ||
| 40: | string didyouknowtext; | |
| 41: | ||
| 42: | public TipOfTheDayView(XmlElement el) | |
| 43: | { | |
| 44: | this.didyouknowtext = Resource.GetString("Dialog.TipOfTheDay.DidYouKnowText"); | |
| 45: | ||
| 46: | icon = Resource.GetBitmap("Icons.TipOfTheDayIcon"); | |
| 47: | ||
| 48: | ||
| 49: | // XmlNodeList nodes = el.GetElementsByTagName("TIP"); | |
| 50: | XmlNodeList nodes = el.ChildNodes; | |
| 51: | ||
| 52: | tips = new string[nodes.Count]; | |
| 53: | for (int i = 0; i < nodes.Count; ++i) { | |
| 54: | tips[i] = StringParser.Parse(nodes[i].InnerText); | |
| 55: | } | |
| 56: | ||
| 57: | curtip = (new Random().Next()) % nodes.Count; | |
| 58: | ||
| 59: | } | |
| 60: | ||
| 61: | protected override void OnPaintBackground(PaintEventArgs pe) | |
| 62: | {} | |
| 63: | ||
| 64: | protected override void OnPaint(PaintEventArgs pe) | |
| 65: | { | |
| 66: | Graphics g = pe.Graphics; | |
| 67: | ||
| 68: | g.FillRectangle(new SolidBrush(Color.Gray), 0, | |
| 69: | 0, | |
| 70: | icon.Width + ICON_DISTANCE, | |
| 71: | Height); | |
| 72: | g.FillRectangle(new SolidBrush(Color.White), 0 + icon.Width + ICON_DISTANCE, | |
| 73: | 0, | |
| 74: | Width - icon.Width - ICON_DISTANCE, | |
| 75: | Height); | |
| 76: | g.DrawImage(icon, 2 + ICON_DISTANCE / 2, 4); | |
| 77: | ||
| 78: | g.DrawString(didyouknowtext, titlefont, new SolidBrush(Color.Black), icon.Width + ICON_DISTANCE + 4, 8); | |
| 79: | ||
| 80: | g.DrawLine(new Pen(Color.Black), new Point(icon.Width + ICON_DISTANCE, 8 + titlefont.Height + 2), | |
| 81: | new Point(Width, 8 + titlefont.Height + 2)); | |
| 82: | drawrect = new Rectangle(icon.Width + ICON_DISTANCE, 8 + titlefont.Height + 6, | |
| 83: | Width - icon.Width - ICON_DISTANCE, Height - (8 + titlefont.Height + 6)); | |
| 84: | ||
| 85: | g.DrawString(tips[curtip], textfont, new SolidBrush(Color.Black), drawrect); | |
| 86: | } | |
| 87: | Rectangle drawrect; | |
| 88: | ||
| 89: | public void NextTip() | |
| 90: | { | |
| 91: | curtip = (curtip + 1) % tips.Length; | |
| 92: | Invalidate(drawrect); | |
| 93: | Update(); | |
| 94: | } | |
| 95: | } | |
| 96: | ||
| 97: | public class TipOfTheDayDialog : Form | |
| 98: | { | |
| 99: | ||
| 100: | private System.ComponentModel.Container components; | |
| 101: | private CheckBox checkBox1; | |
| 102: | private Button button2; | |
| 103: | private Button button1; | |
| 104: | ||
| 105: | Panel panel = new Panel(); | |
| 106: | TipOfTheDayView tipview; | |
| 107: | ||
| 108: | void NextTip(object sender, EventArgs e) | |
| 109: | { | |
| 110: | tipview.NextTip(); | |
| 111: | } | |
| 112: | ||
| 113: | void CheckChange(object sender, EventArgs e) | |
| 114: | { | |
| 115: | Options.SetProperty("SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", checkBox1.Checked); | |
| 116: | } | |
| 117: | ||
| 118: | public TipOfTheDayDialog() | |
| 119: | { | |
| 120: | ||
| 121: | InitializeComponent(); | |
| 122: | StartPosition = FormStartPosition.CenterParent; | |
| 123: | ||
| 124: | Icon = null; | |
| 125: | ||
| 126: | XmlDocument doc = new XmlDocument(); | |
| 127: | doc.Load(Application.StartupPath + "\\..\\data\\options\\TipsOfTheDay.xml" ); | |
| 128: | ||
| 129: | tipview = new TipOfTheDayView(doc.DocumentElement); | |
| 130: | panel.Controls.Add(tipview); | |
| 131: | // panel.FormBorderStyle = FormBorderStyle.Fixed3D; | |
| 132: | Controls.Add(panel); | |
| 133: | ||
| 134: | panel.Width = tipview.Width = Width - 24; | |
| 135: | panel.Height = tipview.Height = button1.Top - 15; | |
| 136: | panel.Location = new Point(8, 5); | |
| 137: | button1.Click += new EventHandler(NextTip); | |
| 138: | ||
| 139: | checkBox1.CheckedChanged += new EventHandler(CheckChange); | |
| 140: | checkBox1.Checked = Boolean.Parse(Options.GetProperty("SharpDevelop.Gui.Dialog.TipOfTheDayView.ShowTipsAtStartup", true).ToString()); | |
| 141: | ||
| 142: | MaximizeBox = MinimizeBox = false; | |
| 143: | ShowInTaskbar = false; | |
| 144: | ||
| 145: | } | |
| 146: | ||
| 147: | /// <summary> | |
| 148: | /// Clean up any resources being used. | |
| 149: | /// </summary> | |
| 150: | protected override void Dispose(bool disposing) | |
| 151: | { | |
| 152: | if (disposing) { | |
| 153: | if (components != null){ | |
| 154: | components.Dispose(); | |
| 155: | } | |
| 156: | } | |
| 157: | base.Dispose(disposing); | |
| 158: | } | |
| 159: | ||
| 160: | private void InitializeComponent() | |
| 161: | { | |
| 162: | this.components = new System.ComponentModel.Container(); | |
| 163: | this.button2 = new Button(); | |
| 164: | this.checkBox1 = new CheckBox(); | |
| 165: | this.button1 = new Button(); | |
| 166: | ||
| 167: | button2.Location = new System.Drawing.Point(328, 232); | |
| 168: | button2.DialogResult = DialogResult.Cancel; | |
| 169: | button2.Size = new System.Drawing.Size(80, 24); | |
| 170: | button2.TabIndex = 1; | |
| 171: | button2.Text = Resource.GetString("Global.CloseButtonText"); | |
| 172: | ||
| 173: | checkBox1.Location = new System.Drawing.Point(8, 232); | |
| 174: | checkBox1.Text = Resource.GetString("Dialog.TipOfTheDay.checkBox1Text"); | |
| 175: | checkBox1.Size = new System.Drawing.Size(210, 24); | |
| 176: | // checkBox1.AccessibleRole = AccessibleRoles.CheckButton; | |
| 177: | checkBox1.TabIndex = 2; | |
| 178: | checkBox1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; | |
| 179: | ||
| 180: | this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); | |
| 181: | this.Text = Resource.GetString("Dialog.TipOfTheDay.DialogName"); | |
| 182: | //@design this.TrayLargeIcon = true; | |
| 183: | this.FormBorderStyle = FormBorderStyle.FixedDialog; | |
| 184: | //@design this.TrayHeight = 0; | |
| 185: | this.ClientSize = new System.Drawing.Size(418, 263); | |
| 186: | ||
| 187: | button1.Location = new System.Drawing.Point(240 - 16, 232); | |
| 188: | button1.Size = new System.Drawing.Size(96, 24); | |
| 189: | button1.TabIndex = 0; | |
| 190: | button1.Text = Resource.GetString("Dialog.TipOfTheDay.button1Text"); | |
| 191: | ||
| 192: | this.Controls.Add(checkBox1); | |
| 193: | this.Controls.Add(button2); | |
| 194: | this.Controls.Add(button1); | |
| 195: | } | |
| 196: | } | |
| 197: | } |
This page was automatically generated by SharpDevelop.