Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

C# - Can't open a different form


  • Please log in to reply

#1
HappyTomato

HappyTomato

    Member

  • Member
  • PipPip
  • 38 posts
hi all..

C# is new to me so I'll be grateful if somebody can give me a hand on this ;)

I'm workng on a C# application that works with a database.. I originally started it as a 'window form' (so normally it is displayed as an icon of a grey window in the treeview solution explorer), but somehow it 'converted' itself into another type of form, displaying itself as an icon that could be for a 'Component class' or 'window service' etc.. so here's my problem:

I created a new window form (lets call it Form2), and added a button in Form1 so the user can navigate themselves to Form2 via a button click from the Form1... however because the two forms seem to be of different 'type' now I can't seem to make a link between them for the users to be able to navigate from one form to another. Here's what I tried:

Form f = new Form2;
f.show();

etc etc..

..which i know works if i had two simpe window forms to work with rather than the two forms that are apparently of different types i've got at the moment:

the trouble is, I have no idea why Form1 had turned into another (unknown) type (I know because the icon is no longer the normal grey window), unfortunately i think this could be the reason why i can't open Form2 from Form1...

I hope this is clear enough.. I really dont know how else to explain it..

Any help is appreciated! thanks in advance :tazz:
  • 0

Advertisements


#2
ratmilk

ratmilk

    Member

  • Member
  • PipPipPip
  • 151 posts
I don't want to sound mean, but i wouldn't suggest learning C#.
For 2 Main reasons:

A) C# is just as slow or slower than VB (it goes through 2 dlls, C only passes through 1)
B) C/C++ is a much better choice.

But if your already stuck into C#, then continue :tazz:
  • 0

#3
BuRnEr

BuRnEr

    Member

  • Member
  • PipPip
  • 48 posts
first of all create two forms and insert this codes on their place..

private Form2 refF2; //create it as variable form1 in class


public Form1() //constractor
{
InitializeComponent();

//add this two lines to form1 constractor
refF2 = new Form2 ();
refF2.refF1 = this;


}

//entery point

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

//button click on first form (form1)
private void button1_Click(object sender, System.EventArgs e)
{
this.Hide();
refF2.Show ();
}


public Form1 refF1; //create this variable form2 in class

//button click on second form (form2)
private void button1_Click(object sender, System.EventArgs e)
{
this.Hide();
refF1.Show();

}

this example demonstrates how we can link forms in this example I created that you can go to form2 from using button on form1 and also you can go to form1 from using button on form2.


And there is a another good solution that I can see up there. Not to go with C# I will try not to go  funny.
I think C# is the future programming language. I m tiered to say C# is good language (of course I get my commission from Microsoft ;) dear Billy pay more than others). I guess some people need to read a lot and a lot. You have long way to go who says C# is not good language. ):tazz:
no comment is acceptable just search read and see ...


have a Good ONE
BuRnEr
  • 0

#4
HappyTomato

HappyTomato

    Member

  • Topic Starter
  • Member
  • PipPip
  • 38 posts
Dear BuRnEr

good on ya for sticking up for C#! I agree with ya!! :tazz: and silly me i found out what the problem was.. it turns out i have overlooked the fact that they were on different namespaces that's why it didn't work lol.. now it's fixed and i can open the other form fine.. thanks anyway for ur help!!!!! ;)

HappyTomato
HappyTomato
  • 0

#5
idosilverwater

idosilverwater

    New Member

  • Member
  • Pip
  • 2 posts
i know c# but i need to know how to link a button to another form i was stack on this problom for weeks and i need the answer before i :) ...
then if some body have the answer then plase write to me.
thank you ,Ido Silverwater
  • 0

#6
idosilverwater

idosilverwater

    New Member

  • Member
  • Pip
  • 2 posts
1234
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP