|
If I understand you correctly, you have a form with a textbox, and a separate class which does some work and is to display text in the textbox?
If yes, then either:
1) the class needs to be given the instance of the form.
or
2) the class needs to signal to the form that data is ready for display.
The first way is pretty trivial, the second is better practice.
Assuming:
myForm formMine = new myForm();
myClass classMine = new myClass();
In the first case, create a field in myClass:
public myForm formDisplayResult;
and assign it after the form and class creation:
myForm formMine = new myForm();
myClass classMine = new myClass();
classMine.formDisplayResult = formMine;
then access the textbox from your class:
formDisplayResult.tbResultsGoHere.Text = "Hello";
In the second case, it is a little more complex:
In myClass:
public partial class myClass
{
public delegate void ChangeHandler(object sender, EventArgs e);
public event ChangeHandler Changed;
protected virtual void OnChanged(EventArgs e)
{
ChangeHandler ch = Changed;
if (ch != null)
{
ch(this, e);
}
}
private void DoSomethingToChangeData()
{
OnChanged(null);
}
}
----- The asign to ch is in case the handler changes between null check
----- and exec.
----- (unlikely, but possible)
----- The null check is to ensure there is a handler. If not, better to
----- ignore it gracefully, than to rely on the thrown exception
----- (NullReferenceException)
In myForm:
myClass classMine = new myClass();
public myForm()
{
classMine.Change += new myClass.ChangeHandler(Changed);
}
private void Changed(object sender, EventArgs e)
{
tbResultsGoHere.Text = classMine.strResults;
}
It is easy really - you just have to get your head around it!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
thx alot, I really appreciate the second one, the first one might be bad habbit
but one thing, does the class inherits from some thing, or its simply
public class className
{
//cnt and others
{
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Either. It makes no real difference for your example.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
As Henry said, it doesn't matter - any class (derived or not) can generate events.
Sorry for the late reply, I was busy making a bulk supply of meatballs...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Good answer!
For future reference, there is no need to create a delegate if using 2.0 or above.
public event ChangeHandler Changed;
can be written as
public event EventHandler Changed;
If custom event args are needed, there is a generic event handler
public event EventHandler<ChangedEventArgs> Changed;
Yay, no more delegate writing when using events
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Thanks!
I didn't know that, I'll give it a try sometime soon. Would be nice to simplify delegate / handler construction a bit...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Well, i think i need more help
for (int i=0; i<count; i++)
{
="" result="i.ToString();
" display="" the="" variable="" contents="" into="" win="" form="" text="" box?
}
how="" can="" i="" send="" content="" winform="" box.=""
<div="" class="ForumSig">Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
I think you mean that your class generates a sequence of results, rather than a single result?
If so, then I would output them to a list and signal to the higher level that there were available.
Specifically, I would set up a queue in your class:
public Queue<string> qsOutputResults = new Queue<string>(100);
(Always create a queue with a minimum size or it gets extended the first time you use it)
Then when your results are available:
qsOutputResults.Enqueue(i.ToString());
OnChanged(null);
This adds the results to the queue and signals the results are ready.
In your form:
private void Changed(object sender, EventArgs e)
{
while (classMine.qsOutputResults.Count > 0)
{
tbResultsGoHere.AppendText(classMine.qsOutputResults.Dequeue());
}
}
Using the queue means they come off in the same order they went on.
If your form is too busy, they will just wait on the queue until you are ready.
You can replace the string with whatever is sensible for your results (of course).
You probably don't want to AppendText (it depends on your app) it was just for example.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
thx dude, that is really appreciated.
the thing which i got concern with, My messsage will not increase than 1000 lines, in each 1000 lines i will clear the textbox contents,
well do i need to use queue for my case, or i should use some other collection for good performance? and if the size of queue increase will it affect the speed and performance of computer?
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
The performance of the queue should be pretty good anyway (except when the size is increased, at which point a new structure has to be created and populated with a copy of the original). Just a case of setting the initial size to a reasonable limit.
If you use another collection (a List<T> for example) then you would have to take care of the FIFO ordering which a Queue guarantees. If you are displaying the latest results (as you seem to) then why re-invent the wheel?
[edit]Removed word "not" from "should not be pretty good" above[/edit]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
thx alot, you helped me alot, thanks again
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
i want to read all the appointments of a outlook 2007 and bind it to DataGridView.
in my application i've add refernce of following library-
Microsoft.Office.Interop.Outlook, Version=12.0.0.0
I'm reading appointments as-
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.ApplicationClass();
Microsoft.Office.Interop.Outlook.NameSpace NS = app.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder objFolder = NS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
foreach (Microsoft.Office.Interop.Outlook._AppointmentItem Item in objFolder.Items)
{
string Id = Item.Subject;
}
but I'm unable to get Item.GlobalAppointmentID .I've search and find there is GlobalAppointmentID propery but I'm unable to get it. plz help me.
|
|
|
|
|
Hello....
In my application i am having a datagriview with columns
Column1 column2 column3
Accountname Debit Credit
-----------------------------------
total debit total credit
The total debit and total credit are two textboxes outside the gridview.
And my gridview is unbound.
Plz help me how i can caluclate all the values in the debit column and get
the result in the toatldebit textbox and similarly credit into total
credit textbox.
Plz someone post me the code...
It's helpful
Thanks in advance...
|
|
|
|
|
Anjani Poornima wrote: Plz someone post me the code...
It is unlikely that you are going to get the entire code here. Have you tried anything?
You can handle the CellLeave event of the gridview and set the value in the textbox. Check the column index of the cell and if it is debit/credit and then set the text of textboxes below.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus
|
|
|
|
|
I am developing one window application. In which I am using crystal report. I want to pass sql query to crystal report programatically from C#.net.
For example: "select * foms staffmaster where id=78"
So how can I create report.
Thanks in advance!
|
|
|
|
|
retrive data in datatable and then simply pass datatable to your report paramater as
myReport.SetDataSource(mydataTable);
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
is that really what you want to do?
i create the database and all the required store procedures in sql server, only then i begin to build c# application
i don´t do any sql in c#, i just trigger a sql SP i want by triggering an event like button click
so, i have a DataGridView to show datatable and i trigger refresh, add, delete, edit row SP procedures for exemple to make changes
i have also crystal reports viewer, but here you will have to built a scheme that is a 100% match your datatable scheme in order to work, DGV doesn´t need that, it "loads" anything regardless the datadable scheme
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
hello
Looking into obfuscating our application binary - I stumbled across
http://rustemsoft.com/SkaterLight.htm[^]
It's free. My question is, is there any "de-facto" methods/tools most commonly used by .NET community which I should check first?
Thanks
dev
|
|
|
|
|
Good question!
Here are the features of the various software options:
http://rustemsoft.com/SkaterDoc/index.html?order.htm[^]
Does anyone know how those features compare to what in in VS2008 Professional? I was asked at work about protecting our IP. I gave it a quick handwave saying that we get a tool in VS2008 Professional software.
Also, I was thinking of doing a direct compile to an X86 hardware base and bypass CLI. I haven't done that yet. It's just something that I read about in one of my .NET books.
Thanks In Advance!
_____________
Joe
|
|
|
|
|
Great thanks
But it does not appear they support 32 bit, and specifically we need office licensing/software lock for 64 bit platform...
dev
|
|
|
|
|
What you should search in an obfuscator, beside strong obfuscation methods (flow control etc.), is string encryption.
My experience in the last few years showed me that the "best" obfuscator out there is Demeanor for .NET[^], which is a commercial software and requires a license fee.
But lately a very interesting freeware tool captured my attention: it's Eazfuscator.NET[^]. It's a great piece of ware, comes with all the needed obfuscation and encryption algortihms, and it's free!
We've been using it in production environments for some months now, and it proved quite effective. Don't be fooled by the looks of the VS integration interface (it doesn't look professional): it's a command line tool and works exactly like other obfuscators.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
whoa thanks - Eazfuscator.NET, is it easy to use?
Looks like Skater.NET is the only option which also offer licensing support
http://rustemsoft.com/SkaterDoc/index.html?order.htm[^]
Lets say if the intention is for my boss to protect his Intellectual Property against me. If I'm the guy who write the licensing code (instead of using third party software like Skater.NET), then would obfuscation software such as Ezafuscator (with no built in licensing) be able to serve this purpose?
Thanks
dev
|
|
|
|
|
Eazfuscator is very easy to use. Like other obfuscators, it's just a command line tool, but it includes a simple interface for VS integration, which will take your project and automatically add a post-generation event to call the utility. You just end up with an obfuscated exe, not much more to be done.
In order to include or exclude classes and pieces of code from obfuscation, it offers some custom attributes.
It does not include any licensing support, so if you need it I guess you'll have to go for Skater or some similar commercial software.
About protecting intellectual property, if your boss wants protection against you (the developer) my opinion is he would be going the wrong way if he thinks to enforce it with obfuscation and licensing.
You write the source code, so you can steal it, either by copying it or by trying to rewrite it. Besides, even with a licensing method not written by you, you can still steal the asymmetric encryption keys and the passwords. If he wants protection against information leakage, I think the correct way is trust and an NDA.
For my projects I decided to write the licensing software myself, cause I don't want to be tied to a third party solution which may not work with future OS releases, or may drop out of the market, or whose pricing strategy may force me to spend high amounts of money in the future. That said, most software houses use pre-cooked licensing solutions and they are more than happy with that.
I think your choice will depend mainly on three factors:
1) Is the cost for the third party solution acceptable (would it cost me more to develop and maintain my own solution) ?
2) Do I have the concrete possibility to develop an in-house solution (time, skill, etc.) ?
3) How much is my software worth against the cost I will pay for licensing (i.e. which is the REAL chance of someone wanting to break it - and succeeding - and which would be the REAL loss I will undergo ? - this in my opinion is the fact most people fail to consider properly) ?
Well, good luck. Let me know how it goes.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Just how does your boss think obfuscation of the executable code would work to protect his IP from the developer who codes with the source? The only way to enforce such protection would be to blindfold you when you sit down...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Moreno:
Thanks!
In my case, the end product is high volume, but the Windows app won't be available to the public. So, my management wouldn't go for any of the hassles or internal bookkeeping costs that goes with a licensing fee.
It looks like I may go with Eazfuscator.NET.
Thanks again!
____
Joe
modified on Sunday, August 2, 2009 3:24 AM
|
|
|
|