|
I am new to C#. I have written a class library in C# that has a form. I want this form to return some value when it terminates. This form is called from some other project.
Lets assume I have a text box [text1] and a button [button1] on the form. When the form loads, user will provide some text in text1 and on clicking button1 the form will terminate and text will be returned.
I want to pass a variable ref to its [form's] constructor, then assign the this reference to some static ref variable so that it could be changed in button1's click event.
In short, I want to modify a constructor's ref parameter in an event procedure.
Thanks in advance,
Vipin.
|
|
|
|
|
Wel..you don't necessarily need to pass a ref variable to the constructor of the form. You can create properties to that form, say:
public string TextValue
{
get{return textBox1.Text}
set{textBox1.Text = value;}
}
All you have to do after that is to show the form with Show() or ShowDialog() and after that you read the value of the TextValue property.
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Passing an argument by reference is not the same thing as passing a reference as an argument. Passing by reference only specifies how the argument is handled in the call to the method, you can't take this behaviour and store it in a variable.
If you want a variable that the methods in the form can change, put the variable in the form class, and make it accessible as a property.
---
"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works. Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it. Anything invented after you're thirty-five is against the natural order of things."
-- Douglas Adams
|
|
|
|
|
It really worked. Thanks a lot.
So I think passing an argument by reference simply creates an alias of passed variable and no memory allocation is done while when a reference is passed as an argument, a reference type of variable is created [so the memory is allocated for it] and it is initialized with the same value [address] as the passing reference variable has. Right?
Thanks again,
Vipin.
|
|
|
|
|
Hi all,
I have little problem, I have a 2 Web applications (C#) and I'm Adding Firts One into Second's Referancecs and I can see First's NameSpaces and Methods without any problem but I have problem accessing Methods, VS can not see them.
Classes and methods are public.
when I press F12 I can see list of methods.
Thanks alot.
|
|
|
|
|
Add a new project with (Class Library) and add all shared functions in that project.
|
|
|
|
|
Try using this in a page within the second project.
<%@ Reference Page="project1_page.aspx" %>
Hope it helps.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
Hello,
I recently saw the following lines of code in the Page_Load block of a Web application and I'm wandering what exactly it does:
Response.AddHeader("pragma","no-cache")
Response.AddHeader("cache-control","private")
Response.CacheControl = "no-cache";
Thanks in advance!
Obi.
//obinnaaj Eof
|
|
|
|
|
|
led mike wrote: They hide that information in the documentation[^]
Curse them and their evil ways.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hey all.
First of all, please keep in mind that i am far from a proffesionel programmer, so dont go to hardcore on me.
The actual Q:
I have made a C# windows form, that connect to a remote mssql database, receives data, and plots it into a gridview. U can also add new data to the sql database. I made it update everytime u focus it, or change values. This however causes the program to hang all the time. Is there anyway to make it update in the background, perhaps every 10 secs, and then just pick of the most reason local version, everytime u focus it? I use tableadapter and dataset to store and edit the data in. Perhaps u could make it update the dataset in the background?
Anyways, i hope u guys understood just a little bit of what my problem is.
1000 x thx in advance
//ev00l
|
|
|
|
|
When you edit the data it is stored locally in the dataset. You then fetch the changes from the dataset and send them to the database as a bulk update. Simply move the database update part to a background worker and you should get much smoother operation. Just watch out though, if you fetch the updates and start sending them to the database you must make sure that you handle new local updates while sending the current ones.
|
|
|
|
|
thx alot for the answer. Perhaps u could explain a little more about backgroundworker (multithreading i guess?) And perhaps some good suggestions to avoid the catch of remote and local updates in the same time.
|
|
|
|
|
ev00l wrote: i am far from a proffesionel programmer
What are you going to try your hand at next? Perhaps build a bridge or dabble at brain surgery?
ev00l wrote: Perhaps u could make it update the dataset in the background?
Yes you can using a thread. Most professional novice programmers are not capable of such endeavors but I'm sure you will be fine... well at least your software can't kill anyone... umm... errr... can it?
|
|
|
|
|
Are you in a bit of a bad mood today Mike?
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: Are you in a bit of a bad mood today Mike?
No way! If you had heard me laughing when I read the OP you would've gotten a different read on my mood.
Now look what happened with ev001... "oh can you explain multi threading to me" ROTFLMA.... yeah, never saw that coming!
|
|
|
|
|
sry for asking questions dude, perhaps the guy had a link to some nice backgroundworker guide. In the future, just ignore my posts, and continue ur sad life as usual.
|
|
|
|
|
ev00l wrote: perhaps the guy had a link to some nice backgroundworker guide.
You mean like this[^]
ev00l wrote: In the future, just ignore my posts, and continue ur sad life as usual.
Thank you! Finally someone realizes that I come to CodeProject so dabbling developers can tell me what to do!
|
|
|
|
|
I actually got it to work with the backgroundworker component and a timer
|
|
|
|
|
ev00l wrote: I actually got it to work
so it probably works and might work again so ship it!
|
|
|
|
|
I wrote a program using an article from Code project as a reference in order to communicate with PIC16F877A using RS232.
I cannot receive any data from the PIC. I tried by sending many data types as, decimal, hex, ASCII eyc... but nothing worked. Plz help me with this, any help would be really appreciated.
THANK YOU
|
|
|
|
|
You want to post this at the bottom of the article- the author should respond.
Also, Hello is not a good subject title.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Hi, lacking a lot of essential information, here are just some ideas:
1.
Sending/receiving text is easier to debug than sending/receiving binary data, so if you
have a choice, start experimenting with text. There are many reasons for this: the serial
driver may react on special characters such as CR, LF, ENQ, ACK, CTRL/S, CTRL/Q, etc, which
are not present in normal text, but obviously can appear in arbitrary binary data.
2.
check connection hardware:
use a terminal emulator such as HyperTerminal to check whether anything comes in. Try a
couple of baud rates. If data is not text and/or baud rate is wrong, you probably will
get strange characters; they would prove connection is present.
3.
check transmission first: sending is much less critical than receiving, so try, if you can,
if things you send actually arrive (maybe there is a command available to toggle a LED
or so).
4.
hardware handshake
if you don't get anything, maybe the sender needs some control lines set before it feels
a need to send something; look for the RTS signal ("Request To Send"), or send a software
dataflow character (try sending a CTRL/Q).
5.
port settings
if you do get something, but it does not look right, try different port settings (baud
rate, parity, ...). Choosing "no parity" gives best chances.
6.
if HyperTerminal works, but your app does not, it still may be a port setting/handshake
problem, or a conceptual mistake in your code. Try the others first and let us know.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Like Malcolm said, you might be better off leaving a message in the discussion forum at the bottom of the article for the author.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi all,
i have some user controls on the form which fetch data from webservice and display them.
the problem is when the form loads it flickers for some time and then all the control are displayed.
Is there any standard solution for this.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|