C# navigating webbrowser from created combobox - c#

I created visual web browser.
private void dodajKartę()
{
web = new WebBrowser();
web.DocumentCompleted += web_DocumentCompleted1;
web.Dock = DockStyle.Fill;
web.Visible = true;
web.ScriptErrorsSuppressed = true;
web.IsWebBrowserContextMenuEnabled = false;
pasek = new ToolStrip();
przyciskWstecz = new ToolStripButton();
przyciskDalej = new ToolStripButton();
pasekAdresu = new ToolStripComboBox();
przyciskZamknijKartę = new ToolStripButton();
przyciskMenu = new ToolStripDropDownButton();
wszystkiePrzyciskiMenu(); // this metod define menu buttons
WszystkoOPrzyciskach(); //this method define ToolStrip buttons
tabControl1.TabPages.Add("Nowa karta");
tabControl1.SelectTab(i);
tabControl1.SelectedTab.Controls.Add(web);
tabControl1.SelectedTab.Controls.Add(pasek);
i += 1;
}
I would like to navigate my browser from created ToolStripComboBox
This code not working:``
((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate((ToolStripComboBox)tabControl1.SelectedTab.Controls[10]).Text;
How can I change this code?

Related

Generate a New Guid into a Textbox area using a button. (C#)

Looking for help.
I have a form which generates fields into a Class extends groupbox.
I am creating a button to clear and then generate a new GUID into a text box but I can seem to access my textbox which has been creating in the Initialize method.
I created a list to store input.
private List<InputSetItem> _inputSetItems = new List<InputSetItem>();
This is where the textbox is created:
public void initialize()
{
//balanceIdentifier
var balanceIdentifierSet = InputGenerator.GenerateInputControl(this, typeof(Guid), "BalanceIdentifier");
Controls.Add(balanceIdentifierSet.Label);
Controls.Add(balanceIdentifierSet.Input);
balanceIdentifierSet.Label.Left = 820;
balanceIdentifierSet.Input.Left = 1050;
balanceIdentifierSet.Input.Width = 400;
balanceIdentifierSet.Label.Top = 20;
balanceIdentifierSet.Input.Top = 20;
_inputSetItems.Add(balanceIdentifierSet);
// btn_Guid
this.btn_Guid.BackColor = System.Drawing.Color.Blue;
this.btn_Guid.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point);
this.btn_Guid.ForeColor = System.Drawing.Color.White;
this.btn_Guid.Location = new System.Drawing.Point(1455, 19);
this.btn_Guid.Name = "btn_Guid";
this.btn_Guid.Size = new System.Drawing.Size(75, 26);
this.btn_Guid.TabIndex = 3;
this.btn_Guid.Text = "GENERATE";
this.btn_Guid.UseVisualStyleBackColor = false;
this.btn_Guid.ImageAlign = ContentAlignment.MiddleRight;
this.btn_Guid.TextAlign = ContentAlignment.MiddleLeft;
// Give the button a flat appearance.
this.btn_Guid.FlatStyle = FlatStyle.Flat;
this.Controls.Add(btn_Guid);
this.btn_Guid.Click += new System.EventHandler(this.generateRandomGuid);
}
This is the UI
This is my Generate Method, I cant wrap my head around accesses and updating this textBox
private void generateRandomGuid(object sender, EventArgs e)
{
var delBal = new InputSetItem();
Guid randomGuid = Guid.NewGuid();
//delBal.btn_Guid.Input = randomGuid.ToString();
//delBal.Input.Text;
}
So figured it out.
I had to create a Control instances
private Control _idemp;
Add the textbox assigning it
var IdempotencyRef = InputGenerator.GenerateInputControl(this, typeof(Guid), "IdempotencyReference");
_idemp = IdempotencyRef.Input;
Controls.Add(IdempotencyRef.Label);
Controls.Add(_idemp);
And then updating the method
private void generateRandomGuid(object sender, EventArgs e)
{
Guid randomGuid = Guid.NewGuid();
_idemp.Text = randomGuid.ToString();
}

How to add button to a previous, manual-created form?

What I'm trying to do is: create a new form with a click (DONE and working, see code below), and then add some buttons to that new form. In this case, it's just one button because I need to make this work before adding more buttons. Should be pretty simple, but after following some Stackoverflow answers/YouTube tutorials/Internet tutorials I'm still not able to do it.
Actually, [the application] It's meant to be like a personal schedule, where I could track every activity or work to do, dispersed over several days (from monday to friday) and in each day you should find the different times of the day (morning/midday/evening).
My code is shown below (this code belongs to the button1_Click method of the first form, as you may notice).
private void button1_Click(object sender, EventArgs e)
{
// día lunes
Form SubLunes = new Form(); // new form
SubLunes.Text = "Día lunes";
SubLunes.Size = new Size(800, 400);
SubLunes.StartPosition = FormStartPosition.CenterScreen;
SubLunes.FormBorderStyle = FormBorderStyle.FixedSingle;
SubLunes.ShowIcon = false;
SubLunes.CreateControl();
SubLunes.ShowDialog();
// botones
Button Mañana = new Button(); // new button
Mañana.Location = new System.Drawing.Point(100, 150);
Mañana.Size = new Size(100, 100);
Mañana.Text = "Mañana";
Mañana.Click += new EventHandler(Mañana_Click);
SubLunes.Controls.Add(Mañana); // should add button to SubLunes
}
private void Mañana_Click(object sender, EventArgs e)
{
MessageBox.Show("hello, i'm new button"); // displayed when clicking new button
}
This is how currently looks:
Main form ///////
After clicking Lunes button (a new Button called 'Mañana' should be in there)
THANKS YOU in advance. See you later.
You're showing the form before creating the button :
Form SubLunes = new Form();
SubLunes.Text = "Día lunes";
SubLunes.Size = new Size(800, 400);
SubLunes.StartPosition = FormStartPosition.CenterScreen;
SubLunes.FormBorderStyle = FormBorderStyle.FixedSingle;
SubLunes.ShowIcon = false;
SubLunes.CreateControl();
SubLunes.ShowDialog();
Button Mañana = new Button();
Mañana.Location = new System.Drawing.Point(100, 150);
Mañana.Size = new Size(100, 100);
Mañana.Text = "Mañana";
Mañana.Click += new EventHandler(Mañana_Click);
SubLunes.Controls.Add(Mañana);
You should create the button before showing the form, like this :
Form SubLunes = new Form();
SubLunes.Text = "Día lunes";
SubLunes.Size = new Size(800, 400);
SubLunes.StartPosition = FormStartPosition.CenterScreen;
SubLunes.FormBorderStyle = FormBorderStyle.FixedSingle;
SubLunes.ShowIcon = false;
SubLunes.CreateControl();
Button Mañana = new Button(); // new button
Mañana.Location = new System.Drawing.Point(100, 150);
Mañana.Size = new Size(100, 100);
Mañana.Text = "Mañana";
Mañana.Click += new EventHandler(Mañana_Click);
SubLunes.Controls.Add(Mañana);
SubLunes.ShowDialog();

how to show inherit groupbox in C#

My english isn't very good.
Hi, I have class where I inherit from GroupBox and I want to use polymorphism and I see in debugger that all is corrent but after compilation I see nothing...
Here is screenshot like it is and how it should be.
grid = new Grid.KierownikGrid();
SetGrid();
private void SetGrid()
{
grid.Location = new System.Drawing.Point(1, 0);
grid.Size = new System.Drawing.Size(10,10);
grid.TabIndex = 10;
grid.TabStop = false;
grid.Text = "";
}
public class KierownikGrid : GroupBox
{
RadioButton addUsers;
RadioButton deleteUsers;
RadioButton troubles;
public KierownikGrid()
:base()
{
Inicjacja();
}
protected void Inicjacja()
{
this.Controls.Add(addUsers = new RadioButton());
this.Controls.Add(deleteUsers = new RadioButton());
this.Controls.Add(troubles = new RadioButton());
this.addUsers.AutoSize = true;
this.addUsers.Checked = true;
this.addUsers.Location = new System.Drawing.Point(3, 10);
this.addUsers.TabIndex = 0;
this.addUsers.TabStop = true;
this.addUsers.Text = "Dodaj użytkownika";
this.addUsers.UseVisualStyleBackColor = true;
this.deleteUsers.AutoSize = true;
this.deleteUsers.Location = new System.Drawing.Point(125, 10);
this.deleteUsers.TabIndex = 1;
this.deleteUsers.Text = "Usuń użytkownika";
this.deleteUsers.UseVisualStyleBackColor = true;
this.troubles.AutoSize = true;
this.troubles.Location = new System.Drawing.Point(250, 10);
this.troubles.TabIndex = 2;
this.troubles.Text = "Problemy";
this.troubles.UseVisualStyleBackColor = true;
}
}
https://i.stack.imgur.com/DFu4t.png
https://i.stack.imgur.com/Dqeim.png
As #BugFinder already mentioned you have to add your control to a form.
There is a tutorial for that.
public class Form1 : System.Windows.Forms.Form
{
//Controls.
private TextBox txtBox = new TextBox();
private Button btnAdd = new Button();
private ListBox lstBox = new ListBox();
private CheckBox chkBox = new CheckBox();
private Label lblCount = new Label();
private void Form1_Load(object sender, EventArgs e)
{
//Add controls to the form.
this.Controls.Add(btnAdd);
this.Controls.Add(txtBox);
this.Controls.Add(lstBox);
this.Controls.Add(chkBox);
this.Controls.Add(lblCount);
}
}

How to use Flow Layout Panel in C#

I am currently working with c# and a flp.
My program uses a loop to add buttons like
I need a third button directly under the red one, to get a view like
Any ideas?
My code:
private void createButton(Entry e)
{
Button newButton = new Button();
newButton.Text = e.title;
newButton.BackColor = System.Drawing.Color.FromArgb(e.colorARGB);
//sizing
newButton.Size = new System.Drawing.Size(300, 60);
newButton.Font = new System.Drawing.Font(newButton.Font.FontFamily, 18);
newButton.Click += new EventHandler(newButton_Click);
newButton.ForeColor = System.Drawing.Color.FromArgb((int)InvertColor((uint)newButton.BackColor.ToArgb()));
newButton.Tag = Link_List.Count - 1;
m_fLPQuickboard.Controls.Add(newButton);
Button newButtonX = new Button();
newButtonX.Text = "X";
newButtonX.BackColor = System.Drawing.Color.FromName("Red");
newButtonX.Size = new System.Drawing.Size(30, 30);
newButtonX.Click += new EventHandler(newButtonX_Click);
newButtonX.Tag = Link_List.Count - 1;
//Tooltips
ToolTip newButtonTooltip = new ToolTip();
newButtonTooltip.SetToolTip(newButton, getParameterFileAsTooltip(e.path));
}

Iterating controls on button click in c# windows application

I am trying to create a windows application where I want to display a group of controls (Combo Box, Text Box and a button) on button click inside a panel.
I have created a code to create controls once but I want to create them again and again on button click one below another.
The code I am using is
public partial class Employee_PayHeads_add : Form
{
private TextBox txtBox = new TextBox();
private Button btnAdd = new Button();
private ComboBox combohead = new ComboBox();
public Employee_PayHeads_add()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.btnAdd.BackColor = Color.Gray;
this.btnAdd.Text = "Remove";
this.btnAdd.Location = new System.Drawing.Point(240, 25);
this.btnAdd.Size = new System.Drawing.Size(70, 25);
this.txtBox.Text = "";
this.txtBox.Location = new System.Drawing.Point(150, 25);
this.txtBox.Size = new System.Drawing.Size(70, 40);
this.combohead.Location = new System.Drawing.Point(10, 25);
panel1.Controls.Add(btnAdd);
panel1.Controls.Add(txtBox);
panel1.Controls.Add(combohead);
}
Also I want a vertical scroller in the panel if number controls overlap the space.
Thanks in advance
Inside the button click event create new objects, instead of using the one you declared before.
Try something like that:
public partial class Employee_PayHeads_add : Form
{
private TextBox txtBox = new TextBox();
private Button btnAdd = new Button();
private ComboBox combohead = new ComboBox();
private int txtBoxStartPosition = 150;
private int btnAddStartPosition = 240;
private int comboheadStartPosition = 10;
}
public Employee_PayHeads_add()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TextBox newTxtBox = new TextBox();
Button newBtnAdd = new Button();
ComboBox newCombohead = new ComboBox();
newBtnAdd.BackColor = Color.Gray;
newBtnAdd.Text = "Remove";
newBtnAdd.Location = new System.Drawing.Point(btnAddStartPosition, 25);
newBtnAdd.Size = new System.Drawing.Size(70, 25);
newTxtBox.Text = "";
newTxtBox.Location = new System.Drawing.Point(txtBoxStartPosition, 25);
newTxtBox.Size = new System.Drawing.Size(70, 40);
newCombohead.Location = new System.Drawing.Point(comboheadStartPosition, 25);
panel1.Controls.Add(newBtnAdd);
panel1.Controls.Add(newTxtBox);
panel1.Controls.Add(newCombohead);
txtBoxStartPosition += 50;
btnAddStartPosition += 50;
comboheadStartPosition += 50;
}
I havent tried your code yet, but it shows that it is always creating the new controls on every click event, but as youo have specified the hardcoaded location for buttons, so it must be creating new controls overlapping each other. so you can change the location dynamically and hopefully it will work
If you want to add the controls again and again you have to create new ones. So rather than defining them in your form like that you have to:
private void button1_Click(object sender, EventArgs e)
{
Button btnAdd = new Button();
btnAdd.BackColor = Color.Gray;
btnAdd.Text = "Remove";
btnAdd.Location = new System.Drawing.Point(240, 25);
btnAdd.Size = new System.Drawing.Size(70, 25);
TextBox txtBox = new TextBox();
txtBox.Text = "";
txtBox.Location = new System.Drawing.Point(150, 25);
txtBox.Size = new System.Drawing.Size(70, 40);
ComboBox combohead = new ComboBox();
combohead.Location = new System.Drawing.Point(10, 25);
panel1.Controls.Add(btnAdd);
panel1.Controls.Add(txtBox);
panel1.Controls.Add(combohead);
}
Now you can remove those private declarations on top of your class.

Categories

Resources