|
This is being over-ambitious.
First go and write a MS-Paint like software. show the world.
Then write and normal Text Editor. Show the world.
Re-improve on those N number of times. Then re-think new idea and then you can Aim for MS-Office kinda via a proper plan.
***** Programme comme si dept soutien technique. est plein de tueurs en série et ils savent adresse de votre domicile. *****
|
|
|
|
|
You've just revealed the Microsoft plan to the entire world. 
|
|
|
|
|
|
Hi,
I have a winforms project with multiple forms that are children of a parent form using the MDI format. Now my main form which is the parent of all the others has a class instance created in the code to do some comms work.
My issue is thatI want to be able to access some of the methods and properties of this instance from my other child forms to for example change some settings etc.
Can someone point me in the right direction please.
example of the code in Main.cs
myClass mainClass = new myClass();
In admin.cs I want to access the PacketSize property of the myClass instance that is created in the Main.cs
Can this be done please say yes...
Cliff.
|
|
|
|
|
Cliffordagius wrote: Can this be done please say yes...
Yes. Have your class implement a custom interface, and cast the form to it's correct interface when you need to access the properties specific to the interface.
Bastard Programmer from Hell
|
|
|
|
|
I say: yes
Furthermore I suggest you choose, buy and study an introductory book on C#, it will teach you the basics of the language and relevant OO principles.
|
|
|
|
|
Declare you mainClass instance at the form level and expose the instance as a property.
internal MyClass MyClass {
get {
return myClass;
}
}
And from the child forms you can access this class like this:
MainForm mainForm = this.MdiParent as MainForm;
if (mainForm != null) {
var packetSize = mainForm.MyClass.PacketSize;
}
|
|
|
|
|
Picky-picky: the use of identical names, for both Property Type, and Property Name, in the 'internal Property definition above ... uhh ... makes me nervous Yes, it will compile, but I think that then becomes ambiguous code that degrades future maintainability.
Consider: we define 'MyClass this way:
public class MyClass
{
public MyClass() {}
public MyClass(int pSize)
{
PacketSize = pSize;
}
public int PacketSize { get; set; }
} Then, in the "main form:"
private static MyClass myClassInstance1;
public static int PacketSizeInMyClass1
{
get
{
return myClassInstance1.PacketSize;
}
}
AdminForm adminForm = new AdminForm();
private void MainForm_Load(object sender, EventArgs e)
{
myClassInstance1 = new MyClass(256);
adminForm.Show();
} Now, in the instance of 'AdminForm, we can directly access the PacketSize value in the instance of MyClass:
int pSize = MainForm.PacketSizeInMyClass1; This is only one variation of many possible approaches to narrowing the scope of what is exposed, and eliminating complex look-ups (as in your example, where you have to re-create the instance of MainForm by de-referencing this.MDIParent every time you want to access the value of PacketSize).
And, each scenario's requirements may demand different approaches: if, using the scenario above there is one and only one instance of MyClass ever created: then that class can be made static, and the code simplified futher.
In the example here, we've gone to perhaps awkward lengths to leave MyClass a dynamic class that could have more than one instance created (although, obviously, we haven't shown any other instantiation and its use).
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Note: having the information about exactly where 'mainClass, and admin.cs instances are created would, imho, focus this question.
This type of question involving exposing fields, methods, etc. across Form boundaries is one of the most frequently asked and answered ones on the C# QA forums.
There are a variety of techniques you can use.
1. injection : have a public variable in admin.cs that holds the instance of mainClass: and when mainClass is created/instantiated: set that public variable in the instance of admin.cs. Note the requirements here: some entity (your main form's code ?) will have to have access to instances of both admin.cs and mainClass.
2. expose the instance of mainClass via a public static property in whatever Form it is created in; using a private 'setter, and a public 'getter is a common practice.
3. create a static class to function in the same way as #2, but, then, why do this, if you only need to expose one instance of one object ? However, if mainClass is instantiated in one semantic entity, and admin.cs is instantiated in another, then this strategy may be necessary.
4. raising events: not relevant here, I think.
My own preference is to keep the "scope" of what is exposed as minimal as possible (which is I why I shudder in horror every time I see .NET code that injects the instance of an entire Form into another). I see this as being consistent with the principle of "separation of concerns."
In this case, if the only data "admin.cs" must have is the 'PacketSize data from mainClass: then consider just exposing a static property, or variable of whatever Type PacketSize is in whatever Form creates the instance of mainClasss, and setting it immediately after mainClass is instantiated.
Then admin.cs can access the property by something like mainClass.PacketSize. If PacketSize is something dynamic that's changing, then use a public static method in mainClass.cs, perhaps to access the current value from the instance of admin.cs.
You'll note I have not mentioned interfaces here: I have a bias against using them in cases where the real use of them is only to expose limited access to data via casting to the interface.
edit ... see response to Shameel's code above for an example of what this post talks about in code ...
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
modified 18-Jan-12 19:03pm.
|
|
|
|
|
I want to open a msg file from disk and perform a Reply action like normal mailitem and display it to user.
Currently i have a datagrid where i show list of msg files .When i right-click on the grid we have context menu for Reply/ReplyAll/Forward option. If a user clicks on any of these action i should be able to open the mailitem in reply/replyall/forward mode.
In Outlook when we click reply for a mailitem it displays the mailitem to user...the same way i want the msg file to be opened to user in reply mode.
Any help is greatly appreciated ... 
|
|
|
|
|
I've been working on a screen scraper application using the WebBrowser class, for an organisation I am involved with. The basic problem is that I get a screen of data that's presented in table form and use the HTMLElement Innertext item to get the raw data, which I then need to parse to extract the bits I want (actual details are not important). However, I have found that the same screenful of information is passed to me in a slightly different format depending on whether my client PC is running XP, Vista or Windows 7. The content is exactly the same but fields are separated by spaces, \r\n or even \r\n\r\n sequences. Has anyone else come across a similar issue, and if so how did you resolve it?
|
|
|
|
|
My two cents on web scraping:
1.
I'd rather use WebClient or HttpWebRequest/HttpWebResponse, unless there is some JavaScript/CSS going on that modified the incoming page before it gets displayed.
2.
as web pages tend to be redesigned all the time, your parser needs to be as tolerant as it possibly can. Therefore I typically try to locate the area of interest based on HTML tags, substring that part, then remove all irrelevant stuff, such as more HTML tags (they suddenly wanted the names in bold, the numbers in a larger font, etc), and reduce whitespace to its essential level (getting rid of \r, \n, \t, multiple spaces, etc). You simply can't just rely on the exact page content, it will break in a matter of days or weeks, and you will be blamed for your app no longer working properly.
PS: when your OS'es vary, so will your IE versions. And they may behave differently from one version to the next (that is the whole idea of having a new version apparently).
|
|
|
|
|
Thanks for the suggestions Luc.
1. I'll take a look at these options, I did not look too closely at existing samples before starting my project.
2. The problem with the main screen is that it is a large table and it looks considerably easier to parse as text rather than going through all the HTML table items.
PS: Of course, that is the obvious answer, thanks again.
|
|
|
|
|
This[^] article may come in handy.
/ravi
|
|
|
|
|
Thanks Ravi, I'll certainly have a look at it.
|
|
|
|
|
I have been looking into your suggestions at point 1, but I have a suspicion it will not fit for what I'm doing (my knowledge of Web apps is very weak). The website is a non-public site so my application has to login to get the information I need. As far as I'm aware, session data such as authentication information is held in the browser, so the Request/Response model will not work for me. Or do you perhaps know an answer to this?
|
|
|
|
|
Richard MacCutchan wrote: Or do you perhaps know an answer to this?
I always have some kind of an answer.
Here I'd say WebBrowser is a high-level Control you can mimick as much as you want based on the lower-level classes I mentioned. I haven't been dealing with session data yet, however I expect it is quite doable. But then it probably doesn't make much sense if WebBrowser offers it for free and you don't have good reasons not to use it.
Maybe Test Http endpoints with WebDev.WebServer, NUnit and Salient.Web.HttpLib[^] coukd help you a bit, mind you it is a search result, I didn't read it.
|
|
|
|
|
Luc Pattyn wrote: I always have some kind of an answer.
Exactly why I addressed my question to you.
|
|
|
|
|
I took your advice and went for the HTML, and it is considerably easier to parse than the raw text. The data I am using changed again recently and the changes I needed to make to my code were much simpler than if I had stuck with text. Thanks for the tips, I now have a much simpler program to maintain and modify.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Look forward to a Tip/Trick on how you parsed the HTML ... with the understanding that the format of your non-public html source may be so unique that what you had to do to parse it just doesn't generalize out to a wider range of scraping/parsing scenarios
best, Bill
"For no man lives in the external truth among salts and acids, but in the warm, phantasmagoric chamber of his brain, with the painted windows and the storied wall." Robert Louis Stevenson
|
|
|
|
|
Sorry, but there was nothing special about what I did, just used the DOM tree to get to the elements I needed and pulled the information from it. It's not the HTML that is the issue but how the content is presented within each element, and I'm sure that the problems I faced (now I understand it a bit better) were the same as any screen scraper. There is nothing special or secret about my code and I'd happily share it but I think there are already a number of articles that describe the process perfectly well; go to Luc's home page for a good start, also JSOP.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Iam a begineer in windows form.So, please someone help me by giving idea how to design windows form that will run always in fullscreen mode.
I tries to design form ,when i run in fullscreen by clicking fullscreen button then all button and lables etc doesn't expand relatively with windows.
|
|
|
|
|
Have a look at the control's anchor and dock proprties. You may also want to look at one of the layout panels such as FlowLayoutPanel or TableLayoutPanel.
|
|
|
|
|
Try setting the forms FormBorderStyle to None and the WindowState to Maximised
"You get that on the big jobs."
|
|
|
|
|
smokindinesh wrote: when i run in fullscreen by clicking fullscreen button then all button and lables etc doesn't expand relatively with windows.
That is the correct behavior. Getting a bigger screen/higher resolution means that there's more that fits on the screen, not that the computer stretches the old screen to fill it. Yes, the form will look differently on different screens, and you'll have to design with that in mind.
A checkbox should always have the default height. It'll become smaller if the resolution goes up, but you shouldn't "rescale"; otherwise your app will look very funny with it's huge checkboxes
You can lock controls in a position, and have them "grow" to fill the remaining space. That wouldn't work (or look) well with a checkbox, but would do the trick on a multiline textbox. Research "Docking" and "Acnhoring" to have them grow with the form.
Bastard Programmer from Hell
|
|
|
|