I am working on a web browser project I want to make a web browser I used ToolStrip to put all the functions of the web browser(favorite, history, home, GO, back, forward). What I want now is to make tha Tabs.
1) what do you think the best way to implement the tabs is it TabControl or is there another way.
2) how do I make to click on a label next to each tab and I open the new tab with a label next to it. So I can open a third one and so on.
I found this code, but it does not add dynamically and it add the second tab with leaving the label on the first tab
this.tabControl1.SelectedTab = tabPage2;
1) i made a tabcontrol and deleted all the tabs in the form
2)i made a button look like a plus and one looks like a minus and added this code:
int Counter = 1;
this.tabControl1.TabPages.Add("Page " + Counter);
this.tabControl1.SelectTab(Counter - 1);
Counter = Counter + 1;
this will add a new tab with title page (1,2,3,4,..,n) and then i put a code when i press go to the specified Url:
RequestAndResponsHelper RS = new RequestAndResponsHelper(Url.Text);
StringBuilder s = new StringBuilder();
s = RS.GetRequest();//get the request from a different class
string HtmlString = s.ToString();
rtb = new RichTextBox();
rtb.AppendText(HtmlString);
rtb.Name = "RichText";
rtb.Dock = DockStyle.Fill;
this.tabControl1.SelectedTab.Controls.Add(rtb);
Related
While working on a small app that pulls test cases, runs, and results from an SQL Server Database, I encountered a dilemma in my methodology for attempting to create dynamic controller names in a TableLayoutPanel in WinForms. I am creating the rows dynamically when the user chooses the particular test case, and from there the TableLayoutPanel will open another window with the test steps preloaded and two radio buttons to indicate whether or not the test passed. My issue is that when I select one of the radio buttons on the right of the step, I get the same console read every single time. I need to be able to determine which exact radio button the user has pressed so I can therefore determine what row it's in and subsequently what test either passed or failed. My main code is as follows:
FormManualTest.cs (section when adding to the TableLayoutPanel)
private void addRowToolStripMenuItem_Click(object sender, EventArgs anotherEvent)
{
tableLayoutTest.RowStyles.Clear(); // Clear row styles to ensure a clean start when adding to the TableLayoutPanel
List<RadioButton> listOfRadioControls = new List<RadioButton>(); // Create array of radio buttons
List<UserCustomStep> listOfStepControls = new List<UserCustomStep>(); // Create array of custom controls
for (int i = 0; i < 5; i++)
{
UserCustomStep step = new UserCustomStep(Counter, "Step: " + i + " Push the button to elicit a response."); // Creates new user custom step control instance
RadioButton pass = new RadioButton();
pass.Text = "Pass";
pass.AutoSize = true;
RadioButton fail = new RadioButton();
fail.Text = "Fail";
fail.AutoSize = true;
fail.Margin = new Padding(3,3,20,3); // Needed to see the fail button without having to scroll over
listOfStepControls.Add(step); // Add step to UserCustomStep array
listOfRadioControls.Add(pass); // Add radio buttons to the RadioButton array
listOfRadioControls.Add(fail);
listOfRadioControls[i * 2].CheckedChanged += (s, e) => // Subscribes the pass radio button to listen for when a user has clicked on it
{
Console.WriteLine("Pass " + i + " was clicked");
};
listOfRadioControls[(i * 2) + 1].CheckedChanged += (s, e) => // Subscribes the fail radio button to listen for when a user has clicked on it
{
Console.WriteLine("Fail " + i + " was clicked");
};
tableLayoutTest.Controls.Add(listOfStepControls[i], 0, i); // Adds CustomStep to first column
tableLayoutTest.Controls.Add(listOfRadioControls[i*2], 1, i); // Adds Pass Radio Button to second column
tableLayoutTest.Controls.Add(listOfRadioControls[(i * 2) + 1], 2, i); // Add Fail Raido Button to third column
Counter++; // Increment couter to add subsequent steps underneath the previous ones.
}
}
Screenshots of App with Console Readout:
After Test Case Has Been Clicked and Radio Button Has Been Pressed
(From clicking this I would expect the console to read "Pass 1 was clicked")
Console Read:
Click Fail Button:
(I know from this image below that since the Pass button doesn't remain clicked I'm somehow using the same controller for all 5 of them)
Console Read
So from all of these issues that I've been presented with, I know that I'm somehow using the same controller for all 5 instances regardless of the fact that I'm storing everything in a controller array and grabbing from there. The for loop will have to be converted to a for each loop later, but that still doesn't solve my issue. I believe that if I could say something like:
RadioButton (pass+id) = new RadioButton();
or something similar while looping through to dynamically create the name for the controls, then each one would be a completely separate control and I could go from there. Any help would be greatly appreciated! I come from a heavy web background so my normal skills to remedy this in JS land aren't coming in handy as of right now. Thanks again for the assistance.
The Name property is optional, you don't need to specify it and it doesn't need to be unique. You can use property Tag for your own purpose (you can assign there ID or event instance of some object).
However you can also create your own control/usercontrol which encapsulate the whole row, and you can declare your own properties exactly for your purpose.
Hello (and sorry for my English), I have a problem with Printing RTF using RichTextBoxPrintCtrl and TabControl.
1) The tabcontrol got no tabs on Design, when the Form Load, it will get a tab with the method AddTab(Title). (Don't mind about other variables).
private void AddTab(string Name = "Nuova Nota*")
{
RichTextBox Body = new RichTextBox();
Body.Name = "Body";
Body.Dock = DockStyle.Fill;
Body.ContextMenuStrip = contextMenuStrip1;
TabPage NewPage = new TabPage();
string DocumentText = Nome;
if (Nome == "Nuova Nota*")
{
TabCount += 1;
DocumentText = Nome + TabCount;
}
NewPage.Name = DocumentText;
NewPage.Text = DocumentText;
tabControl1.Visible = true;
NewPage.Controls.Add(Body);
tabControl1.TabPages.Add(NewPage);
tabControl1.SelectedTab = NewPage;
Nomi_Files.Add(NewPage.Text);
Path_Files.Add("");
}
2) Once the tab is created, you can start to write, change colors, fonts, etc...
To get access on the document that you are making, i use a GetCurrentDocument that return the "Body" of the selected tab:
private RichTextBox GetCurrentDocument
{
get { return (RichTextBox)tabControl1.SelectedTab.Controls["Body"];}
}
Now, all the functions (save, open, fonts, colors...) Works Fine, i wanted to print my document and keep the style, so i Googled and i found this: How to print the content of a RichTextBox control by using Visual C#
I made the RichTextBoxPrintCtrl.dll, added the resource on my project, added the item inside the toolbox, but i can't change the RichTextBox that i create from Code, with RichTextBoxPrintCtrl.
The error that i get is:
Error 1 'RichTextBoxPrintCtrl' is a 'namespace' but is used like a
'type'
How i can use that RichTextBoxPrintCtrl without drag and drop it inside the design form?
Ok, i figured out how to solve it:
instead of declaring like:
RichTextBoxPrintCtrl NameControl = new RichTextBoxPrintCtrl();
we need to declare the namespace so:
RichTextBoxPrintCtrl.RichTextBoxPrintCtrl NameControl = new RichTextBoxPrintCtrl.RichTextBoxPrintCtrl();
Everything works fine :) thanks;
This is the code I have for the button. I want the configbutton to display a pop up window when clicked on. I have looked up and tried a lot of different codes but none of them work. I feel like I am missing a key component but I am not sure what that is. Appreciate the help!
tr = new TableRow();
// Create the cell
tc = new TableCell();
tc.Width = Unit.Point(300);
tc.BorderWidth = 0;
tc.BorderStyle = BorderStyle.None;
Button ConfigButton = new Button();
ConfigButton.Text = "Configuration";
ConfigButton.Visible = true;
tc.Controls.Add(ConfigButton);
tr.Cells.Add(tc);
tbl.Controls.Add(tr);
Using JavaScript Along with ASP.NET you will do the following:
// when you create the button, you can add attributes
Button ConfigButton = new Button();
// this example will display alert dialog box
ConfigButton.Attributes.Add("onclick", "javascript:alert('ALERT ALERT!!!')");
// to get you popup windows
// you would use window.open with the BLANK target
ConfigButton.Text = "Configuration";
ConfigButton.Visible = true;
I recommend looking into using the AJAX Control Toolkit ModalPopupExtender. This is what I use for my pop ups in ASP.NET.
Here is a link to he AJAX Control Toolkit samples website showing how this control works:
http://www.ajaxcontroltoolkit.com/ModalPopup/ModalPopup.aspx
I'm a newbie in c# and probably going to ask a very easy question, but I've not been able to find anything on the web to help.
I have a tabControl with a TabPage which is containing a TextBox object; this object, when the event "Text changed" is invoked, will perform the change of the parent tabPage's name.
The textbox where I typed "text changed by me" has a method which is managing changing the name of the tabPage:
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (this.textBox1.Text != "")
this.tabControl2.SelectedTab.Text = this.textBox1.Text;
else
this.tabControl2.SelectedTab.Text = "(no name)";
}
Into the current page menu is contained a control to add a new page, which runs this method when the user click on it:
private void addNewPageToolStripMenuItem_Click(object sender, EventArgs e)
{
int numPagine;
string strPagine;
numPagine = this.tabControl2.TabCount;
strPagine = numPagine.ToString();
this.tabControl2.TabPages.Add("new page" + strPagine);
}
...and here is the output, which is expected since I'm just asking to add a new empty tabPage:
So, my question is: how can I make possible that when the user is clicking on "Add new page", rather than creating an empty new tabPage the program is rather creating a page like the first one (i.e. containing a textbox into the same position which has a method to change the text of the parent tabPage that I have just created?
Here is an example.
//..
// create the new page
TabPage tpNew = new TabPage("new page..");
// add it to the tab
this.tabControl2.TabPages.Add(tpNew);
// create one labe with text and location like label1
Label lbl = new Label();
lbl.Text = label1.Text;
lbl.Location = label1.Location;
// create a new textbox..
TextBox tbx = new TextBox();
tbx.Location = textBox1.Location;
tpNew.Controls.Add(lbl);
tpNew.Controls.Add(tbx);
// add code to the new textbox via lambda code:
tbx.TextChanged += ( (sender2, evArgs) =>
{
if (tbx.Text != "")
this.tabControl2.SelectedTab.Text = tbx.Text;
else
this.tabControl2.SelectedTab.Text = "(no name)";
} );
For more complicated layout you may want to consider creating a user control..
You also may want to create the first page with this code; the, of course with real values for text and positions!
For creating a UserControl you go to the project tag and right click Add-UserControl-UserControl and name it, maybe myTagPageUC. Then you can do layout on it like on a form. A rather good example is right here on MSDN
The problem is that is has no connection to the form, meaning you'll have to code all sorts of references to make it work..
I'm not really sure if you may not be better off writing a complete clonePage method instead. It could work like the code above, but would loop over the Controls of the template page and check on the various types to add the right controls..
It really depends on what is more complicated: the Layout or the ties between the pages and the form and its other controls..
I have a program where you can enter data into text boxes in a tab control, then save the information you enter for later use. I have an 'Add tab' button, so I can add new tabs and enter new data, unfortunately when I click on the new tab and then go back to the previous tab my saved data in the previous tab has disappeared.
When I close the program and re run it, my data is there again, it is only when I navigate between tabs that my tab data disappears.
How do I make sure my data stays saved when I navigate between tabs?
Here is my add tab button code to give you a better understanding
int seasonYear = 12;
TabPage newTP = new TabPage();
tabControl1.TabPages.Add(newTP)
int TabPageNumber = tabControl1.SelectedIndex + 1; // +1 one up from current
tabControl1.TabPages[TabPageNumber].Text = "Season " + (12 - TabPageNumber);
txtPosition.Clear();
txtPoints.Clear();
txtWon.Clear();
txtDrawn.Clear();
txtLost.Clear();
tabControl1.SelectTab(TabPageNumber);
btnRemovetab.Enabled = true; // We now have something to delete
panel1.Parent = tabControl1.SelectedTab;
ShowData();
}