SRL Archive - C/C++ Help and Tutorials

C# Help


TRiLeZ

2009-06-23 03:35:04

Im making a tabbed web browser, everything is going smooth exept one thing.
If you try to delete the tab when there is only 1 left, the browser breaks.
I know how to fix it… i hide my delete tab button when there is only one tab (when i is 1). It dosnt hide the button though.

Just to let you know my browser starts with the button hidden.
I want to hide the button after you click the delete tab button when i is 1.
How would I do that?

I tryed

if (i == 1) button2.Hide();

It compiles, but dosnt work.

Buckleyindahouse

2009-06-23 03:42:18

if(i == 1)
{

button2.hide();
}

Try that.

Da 0wner

2009-06-23 03:44:32

That looks so close to php code Josh :D.

Buckleyindahouse

2009-06-23 03:45:24

From: Da 0wner
That looks so close to php code Josh :D.

Yep, but it's C# :).

They kinda look alike though.

TRiLeZ

2009-06-23 03:56:33

From: Buckleyindahouse
if(i == 1)
{

button2.hide();
}

Try that.


Still not working :/
Compiles but dosnt work.

Looks like Java

Buckleyindahouse

2009-06-23 04:00:20

post more of the source code?

I could probably help.

TRiLeZ

2009-06-23 04:04:51


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int i = 1;
public Form1()
{
InitializeComponent();
}

private void pictureBox3_Click(object sender, EventArgs e)
{
((WebBrowser)tabControl1.SelectedTab.Controls[0]).Navigate(textBox1.Text);
}

private void tabPage1_Click(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{
WebBrowser Browse = new WebBrowser();
tabControl1.TabPages.Add("Page " + i);
tabControl1.SelectTab(i - 1);
Browse.Name = "wb";
Browse.Dock = DockStyle.Fill;
tabControl1.SelectedTab.Controls.Add(Browse);
((WebBrowser)tabControl1.SelectedTab.Controls[0]).GoHome();
i = i + 1;
button2.Hide();
}

private void pictureBox1_Click(object sender, EventArgs e)
{
((WebBrowser)tabControl1.SelectedTab.Controls[0]).GoBack();
}

private void pictureBox2_Click(object sender, EventArgs e)
{
((WebBrowser)tabControl1.SelectedTab.Controls[0]).GoForward();
}

private void pictureBox4_Click(object sender, EventArgs e)
{
((WebBrowser)tabControl1.SelectedTab.Controls[0]).Refresh();
}

private void pictureBox5_Click(object sender, EventArgs e)
{
((WebBrowser)tabControl1.SelectedTab.Controls[0]).Stop();
}

private void tabPage2_Click(object sender, EventArgs e)
{

}

private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void button1_Click(object sender, EventArgs e)
{
WebBrowser Browse = new WebBrowser();
tabControl1.TabPages.Add("Page " + i);
tabControl1.SelectTab(i - 1);
Browse.Name = "wb";
Browse.Dock = DockStyle.Fill;
tabControl1.SelectedTab.Controls.Add(Browse);
i = i + 1;
button2.Show();
}

private void button2_Click(object sender, EventArgs e)
{
tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
tabControl1.SelectTab(tabControl1.TabPages.Count - 1);
i = i - 1;
//If i is 1 it should hide
}

private void Form1_Activated(object sender, EventArgs e)
{

}
}
}

Thats my whole source so far.

Buckleyindahouse

2009-06-23 04:10:32

At the top, change int i to


Public Static Int i = 1;

See if that works if not, i'll look at source again.

TRiLeZ

2009-06-23 04:23:12

I got it working without changing anything.
All i did was make

private void button2_Click(object sender, EventArgs e)
{
tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
tabControl1.SelectTab(tabControl1.TabPages.Count - 1);
i = i - 1;
if (i == 2) button2.Hide();
}
Instead of

private void button2_Click(object sender, EventArgs e)
{
tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
tabControl1.SelectTab(tabControl1.TabPages.Count - 1);
i = i - 1;
if (i == 1) button2.Hide();
}

Left i as an int.
Now I have to find out why button2 hides when i is 2 and not 1

Bad Processor

2009-08-01 14:58:30

Try

private void button2_Click(object sender, EventArgs e)
{
tabControl1.TabPages.RemoveAt(tabControl1.SelectedIndex);
tabControl1.SelectTab(tabControl1.TabPages.Count - 1);
i = i - 1;
if (i <= 1) button2.Hide();
}

Heh, you using C# Express Edition 2008 or what? I prefer VS2008 Pro for C# :P

– BP

MasterKill

2009-08-01 20:36:41

button2.visible = false; // hides the button

button2.enabled = false; // disables the button

Or just try to debug the value of I, see if it results 1

ShowerThoughts

2009-08-01 20:45:36

Finally something about C#, is it already fixed -.-.
Btw, if I were you I would do something different.
I would make a custom component and then use an array of it then loop through it and place them on the form and you should make them smaller and wider if needed ;).
Need any help or an example pm/msg me.