|
Hello
I created an application that the Main window is calling another window(let call it Second).
from the Second form I want to call a function from the Main form.
so I tried to use Second's constructor to pass the Main form so I can call a public function from the Main form, but c# returns an error.
thats the code:
in Main form:
//the public method
public void Saving()
{
...
}
..
..
//somewhere else in the code, calling the Second window
Second dlgSec = new Second(this);
in Second form:
...
private Form dlgParent;
...
public Second(Form formParent)
{
this.dlgParent = formParent;
InitializeComponent();
}
...
//somewhere in the code, trying to call the function
dlgParent.Saving();
c# cannot find that method.
it does make sense because, because the compiler does not know that I'm going to pass the Main form from the beginning, but I already have done something familier in another application I wrote and it did work, I guess that now I'm missing something and I don't know what.
Can anyone help me with that???
THANKS!!!
|
|
|
|
|
Green Fuze wrote:
public Second(Form formParent)
{
this.dlgParent = formParent;
InitializeComponent();
}
You're downcasting the object to it's base class, you need tochange Form formParent to NameOfMyDerivedFormClass formParent.
Although personally I think this is ugly, and your classes get too tighly coupled. I'd use a delegate to perform this callback.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
okay, got it
Thx alot!
and sorry its ugly, I'm teaching C# myself, so I'm not so comfortable with everything, like delegates.
to be honest, I don't really understand what are delegates, and what they're good for...
|
|
|
|
|
A delegate is a function pointer. An example would be any event in your form, such as Click or Load. You can create your own and use them to pass messages between classes.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
oh, I see! thats much better than what I've done.
okay, I'll sit on that. thanks!
|
|
|
|
|
Delegates are hard to explain in a short message, but they suit what you want quite well.
lets start by defining a delegate
<br />
public delegate void SavingDelegate()
This basically says that im going to pass around a reference to a method that takes no parameters and returns void. This signiture should match your Saving method.
Now pass this to the second form instead of the reference to the parent
private SavingDelegate savingDelegate;
public Second(SavingDelegate mySavingDelegate)
{
this.savingDelegate = mySaqvingDelegate;
}
So when second closes you used to try something like this:
this.myParentForm.Saving()
now you could simply do this:
this.savingDelegate()
(ie, you can "call" the delegate as if its a method.)
So to set this up, from the main form your code may look like
SavingDelegate sd = new SavingDelegate(this.Saving);
Form secondForm = new MyFormName(sd);<br />
secondForm.ShowDialog();
HTH
|
|
|
|
|
|
hey am tryig to recognise a href and get the value so i can build a Uri object with it,
all is good so far except when i encounter a href with javascript in it
can anyone refine my regex pls
<br />
Regex RegexObj = new Regex("<\\s*a\\s+[^>]*href\\s*=\\s*[\"']{1}.+[\"'].*>");<br />
kind regards,
g00fy
|
|
|
|
|
what about
@"<\s*a\s+href\s*=\s*"(.+)"\s*>.+</a>"
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
that wont work
if i test it with
1. <a href='test.ds'>asdf</a>
2. <a href='javascript:go('test.ds')'>asdf</a>
3. <a href="/test.ds">asdf</a>
it will only get the number 3.
but if i use
<\s*a\s+[^>]*href\s*=\s*[\"']{1}.+[\"']{1}>
it will get all 3 and i only wont it to catch 1. & 3.
so i need a character class to exclude the '(' ')' chars but i cant quite get syntax right
so i want to ignore anything that has the brackets in the href or other chars that would not be 'normal' for a href, like, ':'
kind regards,
g00fy
|
|
|
|
|
Hi,
I have a DataTable with a column that is AutoIncrement.
After I clear the DataTable, I would like to have the columns AutoIncrementSeed reset to it's original value... is this possible?
Thanks,
Ron
|
|
|
|
|
You have to use DataTable.Reset() method to retain your autoincrmentseed to it's original position.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Hi Sreejith,
I was hoping not to have to rebuild the datatable columns...
DataTable.Reset() clears the columns.
Ron
|
|
|
|
|
Hi, i was wondering is it is possible to pull out the pixels values and display it out. (eg. pixel 1 ->[2,25,125])
|
|
|
|
|
GetPixel will do this if you have only a few pixels to do. For speed, if you want them all, you should read my image processing articles.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
how many pointers do i need? 1 or 3? sorry abt that i just took up C# because of my project requirements i am rather confused now thanxz in advace
|
|
|
|
|
Soulblazer wrote:
how many pointers do i need?
Do you mean to read an image ? 1. My articles will have several images open at once, as they are applying filters.
Soulblazer wrote:
sorry abt that i just took up C# because of my project requirements
What did you use before/why the move to C# ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i have only learnt Java basic however my supervisor wants us to pick us C# to do this project. i am confused as to i have to pull out the red, green and blue values for all the pixels of the whole picture so i was thinking maybe i would need three pointers one for each color. i have been looking at all 6 of your image processing articles for the pass 1 month++.
|
|
|
|
|
Soulblazer wrote:
i have only learnt Java basic however my supervisor wants us to pick us C# to do this project
They are basically the same thing, so no biggie.
Soulblazer wrote:
i am confused as to i have to pull out the red, green and blue values for all the pixels of the whole picture so i was thinking maybe i would need three pointers one for each color
No - did you read my articles ? The byte array that is returned contains a series of bytes, with three for each pixel, blue, green, then red.
Why do you need to pull all the pixels out ? What will you do with them ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i need to display the pixel values inorder to see clearly how the values changes each function.
|
|
|
|
|
You're showing ALL The pixel values ? Must be a small bitmap, perhaps GetPixel is all you need.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
erm it is a big one but will be cropping out a certain part of the picture to see the values.
|
|
|
|
|
Same deal - if you only want to pull out a small number of values, you may decide to use getpixel, to simplify the code.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
ok thanx i will work on it
|
|
|
|
|
i am doing a quiz web page using visual studio.net
i want to show 1 question per page
but i having trouble displaying the row of data i want.
For my database i created, i having 4 columns
- QnC --- Contains my questions and choices (text)
- QID --- questions identity number
- Choice --- choices identity number
- Ans --- answer (not that important, i havent reach this part)
this is my code for sql:
Cmd.CommandText = "SELECT [QnC] FROM Quiz " +
"WHERE [Choice]= " + i + " and " + "[QID]= " + i + "";
"i" is an integer i declared.
i wanna to display the question and choices but i only get to display question even if i use this code:
Cmd.CommandText = "SELECT [QnC] FROM Quiz " +
" WHERE [Choice]= " + i + "";
For this part the column is empty for the row contain questions.
Please tell me where i goes wrong...
fire85
|
|
|
|