Hello everybody

I Have a doubt

i have created an application in VS2010 for windows application

i have used form1 in form1 i used a button, onclicking on to the button it will load a second form ie.. form2 in which image is added

the overall situation is when i execute the application i'll get form1 and by clicking on the button(which is in form1) it will display the form2 (means it will display the image in the form2)

i want to code in such a way that

for the first time when i click the button the form2 will appear than i'll close the form2
then again when i click the button for the second time the form2 will appear than i'll close the form2
---
---
---
---
--
---
like for the 30th time when i click the button the form2 will appear than i'll close the form2

but the confusion here is

when i click the button for the 31th time the form2 should not appear what ever it may be the form2 should never display again

i am getting totally confused how to do this please help me

Recommended Answers

All 7 Replies

well you can do this

'declare the variable name openNumber 
'and use this code the form1 button click event 
   If openNumber <= 2 Then
            Form2.Show()
            openNumber = openNumber + 1
        Else
            MsgBox("your limit is ended")
        End If

please see the attached file , hope this will solve your issue.

Regards

This is all the code you need:

//on form1:
        int counter;
        Form2 f2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (counter < 5)
            {
                f2 = new Form2();
                counter++;
                f2.Show();
            }
            else
                MessageBox.Show("Form2 cannot be opened any longer.");
        }

If you're trying to do a 30 day trial version, save the # from Mitja Bonca's post to a file and load the # back each time the app loads.

I think that using the registry to save/load your trial #'s is a little more secure than a basic file, if not encrypted properly.

If you're trying to do a 30 day trial version, save the # from Mitja Bonca's post to a file and load the # back each time the app loads.

I think that using the registry to save/load your trial #'s is a little more secure than a basic file, if not encrypted properly.

i didn't understood as you know i am new to C#

if you don't mind can you explain briefly

please
please

As Mitja Bonca's post, declare your Class Level Integer( int counter; ) at the top of the Form's code window, not in a Sub/etc.. This keeps track of how many clicks.
.on Form.Load, check if a certain.File.Exist and if it does, load the file, read it, and set the value from the file to your int counter; . If it does not exist, just skip.
Now, to make it all work, when closing the app, only save "counter" Integer to the same certain.File you checked if existed on Form.Load.

As Mitja Bonca's post, declare your Class Level Integer( int counter; ) at the top of the Form's code window, not in a Sub/etc.. This keeps track of how many clicks.
.on Form.Load, check if a certain.File.Exist and if it does, load the file, read it, and set the value from the file to your int counter; . If it does not exist, just skip.
Now, to make it all work, when closing the app, only save "counter" Integer to the same certain.File you checked if existed on Form.Load.

sorry please don't be anger on me

i didn't understood last two lines of your post

please make it brief..... please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.