How can I show Tooltip text on my own TabPages extends from TabPages just added some extra variables and using DrawItem event.
I've generate them in method.
ISIMtabPage newTab = new ISIMtabPage();
// setting up newTab
string contactName = getContactName(object);
chatFormTabs.TabPages.Add(newTab);
toolTip1.SetToolTip((ISIMtabPage)chatFormTabs.TabPages[chatId], contactName);
But if I hover on the tab it doesn't do anything.
I've TabControl.ShowToolTips enabled.
What should I do?
Thanks in advance.
I would check toolTip1.SetToolTip
example for Tooltip use:
using System.Drawing;
using System.Windows.Forms;
public class Form1 : Form
{
private TabControl tabControl1;
private TabPage tabPage1;
private TabPage tabPage2;
private void MyTabs()
{
this.tabControl1 = new TabControl();
this.tabPage1 = new TabPage();
this.tabPage2 = new TabPage();
this.tabControl1.Controls.AddRange(new Control[] {
this.tabPage1,
this.tabPage2});
this.tabControl1.Location = new Point(35, 25);
this.tabControl1.Size = new Size(220, 220);
// Shows ToolTipText when the mouse passes over tabs.
this.tabControl1.ShowToolTips = true;
// Assigns string values to ToolTipText.
this.tabPage1.ToolTipText = "myTabPage1";
this.tabPage2.ToolTipText = "myTabPage2";
this.Size = new Size(300, 300);
this.Controls.AddRange(new Control[] {
this.tabControl1});
}
public Form1()
{
MyTabs();
}
static void Main()
{
Application.Run(new Form1());
}
}
Actually kinda tricky, so make sure that from the tabControl1 properties "ShowToolTips" is True.
the form1 has a tooltip1 and a TabControl named tabControl1 with multiple tabs for testing
tabControl1 has a collection of tabs
edit the collection and set the tab you want to have the tooltip "ToolTip on toolTip" and ToolTipText to "your message here"
Related
hello I have a problem with TabControl. When I open the second Form it is always empty with no controls or anything.
my code. When I open the first tabpage everything is fine. Everything is in place
private void ShowFormInTabPage(TabPage tp , Form frm)
{
tabControl1.Controls.Add(tp);
frm.TopLevel = false;
tp.Text = frm.Text;
frm.Visible = true;
frm.FormBorderStyle = FormBorderStyle.None;
frm.Dock = DockStyle.Fill;
tabControl1.TabPages[0].Controls.Add(frm);
}
I add form to tabcontrol through such a method. the methods are the same in both cases
private void guna2Button1_Click(object sender, EventArgs e)
{
_tpEmployees = new TabPage();
if (EmployeesForm.IsNull)
{
ShowFormInTabPage(_tpEmployees , EmployeesForm.Instance);
}
else
{
tabControl1.SelectedTab = _tpEmployees;
}
I am having TabControl in which there are multiple tabs. I need to have a functionality in which if I 'drag a tab' or 'right click on tab -> float' then that tab comes out from tabs list and becomes free float window(or a winform) which can be moved anywhere on the screen. And vice Versa.
Here is the code for the TabControl-
TabControl tabControl = new TabControl();
TabPage tabPage1 = new TabPage();
tabPage1.Text = "Tab Page 1";
TabPage tabPage2 = new TabPage();
tabPage2.Text = "Tab Page 2";
tabControl.Controls(tabPage1);
tabControl.Controls(tabPage2);
Please use below code for swaping Tab-Page controls to Form and vise-versa. Please note that instead of adding controls to Tab-Page, you need to first add controls in a panel and then that panel need to be added to the Tab_Page:
private void Button1_Click(object sender, EventArgs e)
{
TabPage tabPage1 = (TabPage) sender;
Form frm = new Form();
frm.Text = tabPage1.Text;
Panel panel = (Panel) tabPage1.Controls[0];
tabPage1.Controls.RemoveAt(0);
tabControl.TabPages.Remove(tabPage1);
frm.Controls.Add(panel);
frm.Show();
}
private void Form1_Click(object sender, EventArgs e)
{
Form frm = (Form) sender;
TabPage tabPage1 = new TabPage();
tabPage1.Text = frm.Text;
Panel panel = (Panel)frm.Controls[0];
frm.Controls.RemoveAt(0);
tabControl.TabPages.Add(tabPage1);
frm.Controls.RemoveAt(0);
frm.Hide();
}
Im trying to write this simple winform menu and I need to add the contents of the NBox text box to a string so I can display it when a button is pressed, however I keep getting the error that NBox does not exist in the current context. So, how would i got about making the contents of the text box available at the press of a button?
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
//namespace game{
class MainM : Form{
public MainM(){
Text = "Adventures Main Menu";
Size = new Size(400,400);
//NameBox
TextBox NBox = new TextBox();
NBox.Location = new Point(145, 100);
NBox.Size = new Size(200, 30);
//Title Label
Label title = new Label();
title.Text = "ADVENTURE THE GAME";
title.Location = new Point(145, 30);
title.Size = new Size(200,60);
title.Font = new Font(defaultFont.FontFamily, defaultFont.Size, FontStyle.Bold);
//The main menu Buttons and all that jazz
Button credits = new Button();
Button start = new Button();
//Credits Button
credits.Text = "Credits";
credits.Size = new Size(75,20);
credits.Location = new Point(145,275);
credits.Click += new EventHandler(this.credits_button_click);
//Start Button
start.Text = "Start";
start.Size = new Size(75,20);
start.Location = new Point(145,200);
start.Click += new EventHandler(this.start_button_click);
//Control addition
this.Controls.Add(title);
this.Controls.Add(credits);
this.Controls.Add(start);
this.Controls.Add(NBox);
}
public void test(){
//The Main Window
}
private void credits_button_click(object sender, EventArgs e){
MessageBox.Show("Created by: Me");
}
private void start_button_click(object sender, EventArgs e){
this.Hide();
string name = NBox.Text;
MessageBox.Show(name);
//Process.Start("TextGame.exe");
}
public static void Main(){
Application.Run(new MainM());
}
}
//}
First, you need to name the control, that name will be its key in container's Controls collection :
//NameBox
TextBox NBox = new TextBox();
NBox.Location = new Point(145, 100);
NBox.Size = new Size(200, 30);
NBox.Name = "NBox"; //Naming the control
Then you will be able to retrieve it from the container:
private void start_button_click(object sender, EventArgs e){
this.Hide();
TextBox NBox= (TextBox)Controls.Find("NBox", true)[0];//Retrieve controls by name
string name = NBox.Text;
MessageBox.Show(name);
//Process.Start("TextGame.exe");
}
You declared NBox in consturctor and it is visible only inside constructor. You need to move it outside of constructor.
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
//namespace game{
class MainM : Form{
TextBox NBox;
public MainM(){
Text = "Adventures Main Menu";
Size = new Size(400,400);
//NameBox
NBox = new TextBox();
...
public static object loadForm(Form formToLoad, TabControl homeTabControl)
{
//Check if formToLoad parameter is NULL
if (formToLoad == null) throw new ArgumentNullException("formToLoad");
//get the parent/ownining form
Form form1 = new Form1();
//set formToLoad properties
formToLoad = new Form
{
Owner = form1,
FormBorderStyle = FormBorderStyle.None,
TopLevel = false,
Dock = DockStyle.Fill
};
//add formToLoad to tabControl tabPage
homeTabControl.TabPages["tabPageHome"].Controls.Add(formToLoad);
formToLoad.Show();
return formToLoad;
}
How come formToLoad does not show in the tabControl Page when i call my code from a button click?
private void button3_Click(object sender, EventArgs e)
{
LeaveMainForm lM = new LeaveMainForm();
AppCode.FormLoader.loadForm(lM, homeTabControl);
}
You are over-writing the actual form you are trying to load with a new Form instance, in this line :
formToLoad = new Form
Try this :
//set formToLoad properties
formToLoad.Owner = form1;
formToLoad.FormBorderStyle = FormBorderStyle.None;
formToLoad.TopLevel = false;
formToLoad.Dock = DockStyle.Fill;
Can i know how can i make a popup bubble message in my application coded in C#.
Like example, when i start my application, it'll popup saying "Welcome to UbuntuSE App".
And yea, The popup is not the message box popup, it's the popup in the traymenu.
Something similar to this:
PS,
If i'm not wrong, this is called Balloon Tooltips. But how can i use this in my codes.
If you're using Winforms you have the NotifyIcon class. This object has a ShowBalloonTip method which will show a balloon tip:
var icon = new NotifyIcon();
icon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)
you must be looking for the Notify Icon Control
another CodeProject Example
here is a full example in MSDN
You can use the NotifyIcon control that's part of .NET 2.0 System.Windows.Forms.
Check : Using the NotifyIcon control
From the msdn,
NotifyIcon : Specifies a component that creates an
icon in the notification area. This
class cannot be inherited.
NotifyIcon.BalloonTipIcon
You have to set the property "icon" or it won't pop up
NotifyIcon ballon = new NotifyIcon();
ballon.Icon = SystemIcons.Application;//or any icon you like
ballon.ShowBalloonTip(1000, "Balloon title", "Balloon text", ToolTipIcon.None)
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
namespace ShowToolTip
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btBallonToolTip_Click(object sender, EventArgs e)
{
ShowBalloonTip();
this.Hide();
}
private void ShowBalloonTip()
{
Container bpcomponents = new Container();
ContextMenu contextMenu1 = new ContextMenu();
MenuItem runMenu = new MenuItem();
runMenu.Index = 1;
runMenu.Text = "Run...";
runMenu.Click += new EventHandler(runMenu_Click);
MenuItem breakMenu = new MenuItem();
breakMenu.Index = 2;
breakMenu.Text = "-------------";
MenuItem exitMenu = new MenuItem();
exitMenu.Index = 3;
exitMenu.Text = "E&xit";
exitMenu.Click += new EventHandler(exitMenu_Click);
// Initialize contextMenu1
contextMenu1.MenuItems.AddRange(
new System.Windows.Forms.MenuItem[] { runMenu, breakMenu, exitMenu });
// Initialize menuItem1
this.ClientSize = new System.Drawing.Size(0, 0);
this.Text = "Ballon Tootip Example";
// Create the NotifyIcon.
NotifyIcon notifyIcon = new NotifyIcon(bpcomponents);
// The Icon property sets the icon that will appear
// in the systray for this application.
string iconPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + #"\setup-icon.ico";
notifyIcon.Icon = new Icon(iconPath);
// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon.ContextMenu = contextMenu1;
notifyIcon.Visible = true;
// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon.Text = "Morgan Tech Space BallonTip Running...";
notifyIcon.BalloonTipText = "Morgan Tech Space BallonTip Running...";
notifyIcon.BalloonTipTitle = "Morgan Tech Space";
notifyIcon.ShowBalloonTip(1000);
}
void exitMenu_Click(object sender, EventArgs e)
{
this.Close();
}
void runMenu_Click(object sender, EventArgs e)
{
MessageBox.Show("BallonTip is Running....");
}
}
}
Thanks for the info!
Made something like this and worked!
private void NotifyBaloon(string text, string tooltip, string title, bool show)
{
notifyIconMain.Text = text;
notifyIconMain.BalloonTipText = tooltip;
notifyIconMain.BalloonTipTitle = title;
if (show)
notifyIconMain.ShowBalloonTip(1000);
}