daily pastebin goal
54%
SHARE
TWEET

Untitled

a guest Dec 15th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Form1_MouseMove(object sender, MouseEventArgs e)
  2.     {
  3.         m_toolTips.SetToolTip(this, "testing tooltip on " + DateTime.Now.ToString());
  4.         string tipText = this.m_toolTips.GetToolTip(this);
  5.         if ((tipText != null) && (tipText.Length > 0))
  6.         {
  7.             Point clientLoc = this.PointToClient(Cursor.Position);
  8.             Control child = this.GetChildAtPoint(clientLoc);
  9.             if (child != null && child.Enabled == false)
  10.             {
  11.                 m_toolTips.ToolTipTitle = "MouseHover On Disabled Control";
  12.                 m_toolTips.Show(tipText, this, 10000);
  13.             }
  14.             else
  15.             {
  16.                 m_toolTips.ToolTipTitle = "MouseHover Triggerd";
  17.                 m_toolTips.Show(tipText, this, 3000);
  18.             }
  19.         }
  20.     }
  21.    
  22. private ToolTip     _toolTip = new ToolTip();
  23. private Control     _currentToolTipControl = null;
  24.  
  25. public Form1()
  26. {
  27.     InitializeComponent();
  28.  
  29.     _toolTip.SetToolTip(this.button1, "My button1");
  30.     _toolTip.SetToolTip(this.button2, "My button2");
  31.     _toolTip.SetToolTip(this.textBox1, "My text box");
  32. }
  33.  
  34. private void Form1_MouseMove(object sender, MouseEventArgs e)
  35. {
  36.     Control control = GetChildAtPoint(e.Location);
  37.     if (control != null)
  38.     {
  39.         if (!control.Enabled && _currentToolTipControl == null)
  40.         {
  41.             string toolTipString = _toolTip.GetToolTip(control);
  42.             // trigger the tooltip with no delay and some basic positioning just to give you an idea
  43.             _toolTip.Show(toolTipString, control, control.Width/2, control.Height/2);
  44.             _currentToolTipControl = control;
  45.         }
  46.     }
  47.     else
  48.     {
  49.         if (_currentToolTipControl != null) _toolTip.Hide(_currentToolTipControl);
  50.         _currentToolTipControl = null;
  51.     }
  52. }
  53.    
  54. void OrderSummaryDetails_MouseMove(object sender, MouseEventArgs e)
  55. {
  56.       Control control = GetChildAtPoint(e.Location);
  57.       if (control != null)
  58.       {
  59.           string toolTipString = mFormTips.GetToolTip(control);
  60.           this.mFormTips.ShowAlways = true;
  61.           // trigger the tooltip with no delay and some basic positioning just to give you an idea
  62.           mFormTips.Show(toolTipString, control, control.Width / 2, control.Height / 2);
  63.       }
  64. }
  65.    
  66. public partial class MyTextBox : UserControl
  67. {
  68.    ...
  69.    ...
  70.    ...
  71.  
  72.  
  73.    public void DisableMyTextBox()
  74.     {
  75.         this.txt.Enabled = false;  //txt is the name of Winform-Textbox from my designer
  76.         this.Enabled = true;
  77.     }
  78.  
  79.     public void EnableMyTextBox()
  80.     {
  81.         this.txt.Enabled = true;
  82.         this.Enabled = true;
  83.     }
  84.  
  85.     //set the tooltip from properties tab in designer or wherever
  86. }
  87.    
  88. using System;
  89. using System.Collections.Generic;
  90. using System.ComponentModel;
  91. using System.Data;
  92. using System.Drawing;
  93. using System.Linq;
  94. using System.Text;
  95. using System.Windows.Forms;
  96.  
  97. namespace WindowsFormsApplication1
  98. {
  99.     public partial class Form1 : Form
  100.     {
  101.         public Form1()
  102.         {
  103.             InitializeComponent();
  104.         }
  105.  
  106.         private void Form1_Load(object sender, EventArgs e)
  107.         {
  108.  
  109.         }
  110.  
  111.         private void cb_ADC_RPA0_CheckedChanged(object sender, EventArgs e)
  112.         {
  113.             /* Disable pin on other peripherals */
  114.             cb_UART_RPA0.Enabled = !((CheckBox)sender).Checked;
  115.             cb_PWM_RPA0.Enabled = !((CheckBox)sender).Checked;
  116.  
  117.             SetTootTip((CheckBox)sender, lbl_PWM_RPA0, lbl_UART_RPA0, "ADC");
  118.  
  119.         }
  120.  
  121.  
  122.  
  123.         private void cb_PWM_RPA0_CheckedChanged(object sender, EventArgs e)
  124.         {
  125.             /* Disable pin on other peripherals */
  126.             cb_UART_RPA0.Enabled = !((CheckBox)sender).Checked;
  127.             cb_ADC_RPA0.Enabled = !((CheckBox)sender).Checked;
  128.  
  129.             SetTootTip((CheckBox)sender, lbl_ADC_RPA0, lbl_UART_RPA0, "PWM");
  130.         }
  131.  
  132.         private void cb_UART_RPA0_CheckedChanged(object sender, EventArgs e)
  133.         {
  134.             /* Disable pin on other peripherals */
  135.             cb_ADC_RPA0.Enabled = !((CheckBox)sender).Checked;
  136.             cb_PWM_RPA0.Enabled = !((CheckBox)sender).Checked;
  137.             SetTootTip((CheckBox)sender, lbl_ADC_RPA0, lbl_PWM_RPA0, "UART");
  138.  
  139.         }
  140.  
  141.         void SetTootTip(CheckBox sender, Label lbl1, Label lbl2, string text)
  142.         {
  143.             /* Update tooltip on the other labels */
  144.             if (sender.Checked)
  145.             {
  146.                 toolTip1.SetToolTip(lbl1, "Used by " + text);
  147.                 toolTip1.SetToolTip(lbl2, "Used by " + text);
  148.             }
  149.             else
  150.             {
  151.                 toolTip1.SetToolTip(lbl1, "");
  152.                 toolTip1.SetToolTip(lbl2, "");
  153.             }
  154.         }
  155.     }
  156. }
  157.  
  158.  
  159. namespace WindowsFormsApplication1
  160. {
  161.     partial class Form1
  162.     {
  163.         /// <summary>
  164.         /// Required designer variable.
  165.         /// </summary>
  166.         private System.ComponentModel.IContainer components = null;
  167.  
  168.         /// <summary>
  169.         /// Clean up any resources being used.
  170.         /// </summary>
  171.         /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  172.         protected override void Dispose(bool disposing)
  173.         {
  174.             if (disposing && (components != null))
  175.             {
  176.                 components.Dispose();
  177.             }
  178.             base.Dispose(disposing);
  179.         }
  180.  
  181.         #region Windows Form Designer generated code
  182.  
  183.         /// <summary>
  184.         /// Required method for Designer support - do not modify
  185.         /// the contents of this method with the code editor.
  186.         /// </summary>
  187.         private void InitializeComponent()
  188.         {
  189.             this.components = new System.ComponentModel.Container();
  190.             this.tabControl1 = new System.Windows.Forms.TabControl();
  191.             this.tpPWM = new System.Windows.Forms.TabPage();
  192.             this.tpUART = new System.Windows.Forms.TabPage();
  193.             this.tpADC = new System.Windows.Forms.TabPage();
  194.             this.cb_PWM_RPA0 = new System.Windows.Forms.CheckBox();
  195.             this.cb_ADC_RPA0 = new System.Windows.Forms.CheckBox();
  196.             this.lbl_PWM_RPA0 = new System.Windows.Forms.Label();
  197.             this.lbl_ADC_RPA0 = new System.Windows.Forms.Label();
  198.             this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
  199.             this.lbl_UART_RPA0 = new System.Windows.Forms.Label();
  200.             this.cb_UART_RPA0 = new System.Windows.Forms.CheckBox();
  201.             this.tabControl1.SuspendLayout();
  202.             this.tpPWM.SuspendLayout();
  203.             this.tpUART.SuspendLayout();
  204.             this.tpADC.SuspendLayout();
  205.             this.SuspendLayout();
  206.             //
  207.             // tabControl1
  208.             //
  209.             this.tabControl1.Controls.Add(this.tpPWM);
  210.             this.tabControl1.Controls.Add(this.tpUART);
  211.             this.tabControl1.Controls.Add(this.tpADC);
  212.             this.tabControl1.Location = new System.Drawing.Point(12, 12);
  213.             this.tabControl1.Name = "tabControl1";
  214.             this.tabControl1.SelectedIndex = 0;
  215.             this.tabControl1.Size = new System.Drawing.Size(629, 296);
  216.             this.tabControl1.TabIndex = 0;
  217.             //
  218.             // tpPWM
  219.             //
  220.             this.tpPWM.Controls.Add(this.lbl_PWM_RPA0);
  221.             this.tpPWM.Controls.Add(this.cb_PWM_RPA0);
  222.             this.tpPWM.Location = new System.Drawing.Point(4, 22);
  223.             this.tpPWM.Name = "tpPWM";
  224.             this.tpPWM.Padding = new System.Windows.Forms.Padding(3);
  225.             this.tpPWM.Size = new System.Drawing.Size(621, 270);
  226.             this.tpPWM.TabIndex = 0;
  227.             this.tpPWM.Text = "PWM";
  228.             this.tpPWM.UseVisualStyleBackColor = true;
  229.             //
  230.             // tpUART
  231.             //
  232.             this.tpUART.Controls.Add(this.cb_UART_RPA0);
  233.             this.tpUART.Controls.Add(this.lbl_UART_RPA0);
  234.             this.tpUART.Location = new System.Drawing.Point(4, 22);
  235.             this.tpUART.Name = "tpUART";
  236.             this.tpUART.Padding = new System.Windows.Forms.Padding(3);
  237.             this.tpUART.Size = new System.Drawing.Size(621, 270);
  238.             this.tpUART.TabIndex = 1;
  239.             this.tpUART.Text = "UART";
  240.             this.tpUART.UseVisualStyleBackColor = true;
  241.             //
  242.             // tpADC
  243.             //
  244.             this.tpADC.Controls.Add(this.lbl_ADC_RPA0);
  245.             this.tpADC.Controls.Add(this.cb_ADC_RPA0);
  246.             this.tpADC.Location = new System.Drawing.Point(4, 22);
  247.             this.tpADC.Name = "tpADC";
  248.             this.tpADC.Padding = new System.Windows.Forms.Padding(3);
  249.             this.tpADC.Size = new System.Drawing.Size(621, 270);
  250.             this.tpADC.TabIndex = 2;
  251.             this.tpADC.Text = "ADC";
  252.             this.tpADC.UseVisualStyleBackColor = true;
  253.             //
  254.             // cb_PWM_RPA0
  255.             //
  256.             this.cb_PWM_RPA0.AutoSize = true;
  257.             this.cb_PWM_RPA0.Location = new System.Drawing.Point(17, 65);
  258.             this.cb_PWM_RPA0.Name = "cb_PWM_RPA0";
  259.             this.cb_PWM_RPA0.Size = new System.Drawing.Size(15, 14);
  260.             this.cb_PWM_RPA0.TabIndex = 0;
  261.             this.cb_PWM_RPA0.UseVisualStyleBackColor = true;
  262.             this.cb_PWM_RPA0.CheckedChanged += new System.EventHandler(this.cb_PWM_RPA0_CheckedChanged);
  263.             //
  264.             // cb_ADC_RPA0
  265.             //
  266.             this.cb_ADC_RPA0.AutoSize = true;
  267.             this.cb_ADC_RPA0.Location = new System.Drawing.Point(17, 65);
  268.             this.cb_ADC_RPA0.Name = "cb_ADC_RPA0";
  269.             this.cb_ADC_RPA0.Size = new System.Drawing.Size(15, 14);
  270.             this.cb_ADC_RPA0.TabIndex = 1;
  271.             this.cb_ADC_RPA0.UseVisualStyleBackColor = true;
  272.             this.cb_ADC_RPA0.CheckedChanged += new System.EventHandler(this.cb_ADC_RPA0_CheckedChanged);
  273.             //
  274.             // lbl_PWM_RPA0
  275.             //
  276.             this.lbl_PWM_RPA0.AutoSize = true;
  277.             this.lbl_PWM_RPA0.Location = new System.Drawing.Point(38, 65);
  278.             this.lbl_PWM_RPA0.Name = "lbl_PWM_RPA0";
  279.             this.lbl_PWM_RPA0.Size = new System.Drawing.Size(35, 13);
  280.             this.lbl_PWM_RPA0.TabIndex = 1;
  281.             this.lbl_PWM_RPA0.Text = "RPA0";
  282.             //
  283.             // lbl_ADC_RPA0
  284.             //
  285.             this.lbl_ADC_RPA0.AutoSize = true;
  286.             this.lbl_ADC_RPA0.Location = new System.Drawing.Point(38, 66);
  287.             this.lbl_ADC_RPA0.Name = "lbl_ADC_RPA0";
  288.             this.lbl_ADC_RPA0.Size = new System.Drawing.Size(35, 13);
  289.             this.lbl_ADC_RPA0.TabIndex = 2;
  290.             this.lbl_ADC_RPA0.Text = "RPA0";
  291.             //
  292.             // lbl_UART_RPA0
  293.             //
  294.             this.lbl_UART_RPA0.AutoSize = true;
  295.             this.lbl_UART_RPA0.Location = new System.Drawing.Point(37, 65);
  296.             this.lbl_UART_RPA0.Name = "lbl_UART_RPA0";
  297.             this.lbl_UART_RPA0.Size = new System.Drawing.Size(35, 13);
  298.             this.lbl_UART_RPA0.TabIndex = 4;
  299.             this.lbl_UART_RPA0.Text = "RPA0";
  300.             //
  301.             // cb_UART_RPA0
  302.             //
  303.             this.cb_UART_RPA0.AutoSize = true;
  304.             this.cb_UART_RPA0.Location = new System.Drawing.Point(16, 65);
  305.             this.cb_UART_RPA0.Name = "cb_UART_RPA0";
  306.             this.cb_UART_RPA0.Size = new System.Drawing.Size(15, 14);
  307.             this.cb_UART_RPA0.TabIndex = 5;
  308.             this.cb_UART_RPA0.UseVisualStyleBackColor = true;
  309.             this.cb_UART_RPA0.CheckedChanged += new System.EventHandler(this.cb_UART_RPA0_CheckedChanged);
  310.             //
  311.             // Form1
  312.             //
  313.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  314.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  315.             this.ClientSize = new System.Drawing.Size(758, 429);
  316.             this.Controls.Add(this.tabControl1);
  317.             this.Name = "Form1";
  318.             this.Text = "Form1";
  319.             this.Load += new System.EventHandler(this.Form1_Load);
  320.             this.tabControl1.ResumeLayout(false);
  321.             this.tpPWM.ResumeLayout(false);
  322.             this.tpPWM.PerformLayout();
  323.             this.tpUART.ResumeLayout(false);
  324.             this.tpUART.PerformLayout();
  325.             this.tpADC.ResumeLayout(false);
  326.             this.tpADC.PerformLayout();
  327.             this.ResumeLayout(false);
  328.  
  329.         }
  330.  
  331.         #endregion
  332.  
  333.         private System.Windows.Forms.TabControl tabControl1;
  334.         private System.Windows.Forms.TabPage tpPWM;
  335.         private System.Windows.Forms.Label lbl_PWM_RPA0;
  336.         private System.Windows.Forms.CheckBox cb_PWM_RPA0;
  337.         private System.Windows.Forms.TabPage tpUART;
  338.         private System.Windows.Forms.TabPage tpADC;
  339.         private System.Windows.Forms.Label lbl_ADC_RPA0;
  340.         private System.Windows.Forms.CheckBox cb_ADC_RPA0;
  341.         private System.Windows.Forms.ToolTip toolTip1;
  342.         private System.Windows.Forms.CheckBox cb_UART_RPA0;
  343.         private System.Windows.Forms.Label lbl_UART_RPA0;
  344.     }
  345. }
  346.    
  347. public partial class TooltipButton : UserControl
  348. {
  349.     public TooltipButton()
  350.     {
  351.         InitializeComponent();
  352.     }
  353.  
  354.     public new bool Enabled
  355.     {
  356.         get { return button.Enabled; }
  357.         set { button.Enabled = value; }
  358.     }
  359.  
  360.     [Category("Appearance")]
  361.     [Description("The text displayed by the button.")]
  362.     [EditorBrowsable(EditorBrowsableState.Always)]
  363.     [Browsable(true)]
  364.     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
  365.     [Bindable(true)]
  366.     public override string Text
  367.     {
  368.         get { return button.Text; }
  369.         set { button.Text = value; }
  370.     }
  371.  
  372.     [Category("Action")]
  373.     [Description("Occurs when the button is clicked.")]
  374.     [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
  375.     public new event EventHandler Click;
  376.  
  377.     private void button_Click(object sender, EventArgs e)
  378.     {
  379.         // Bubble event up to parent
  380.         Click?.Invoke(this, e);
  381.     }
  382. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top