dude totally...
You'd want to store the position of the rect somewhere, so i'd suggest not just incrementing/decrementing its position based on button presses without actually changing a stored variable's position.
Printable View
dude totally...
You'd want to store the position of the rect somewhere, so i'd suggest not just incrementing/decrementing its position based on button presses without actually changing a stored variable's position.
oh, ok. Thanks for showing me how to do it. I have never seen that way before, so i dont totally understand it... I'll post up if i have problems :D
uh... how do i use the KeyPressEvent? i have the event, but i dont know what to do to make anything happen if i click DOWN or something like that
The first thing that entered my mind, was:
but that obviously doesn't work. How do i get my program to know if i've pressed a button!?Code:static void keyboard(object objSender, KeyPressEventArgs aep)
{
Keys test = new Keys();
if(test == Keys.Enter)
{
Form pop = new Form();
pop.Text = "bob";
pop.Show();
}
}
:(
Come on ... Its really time now. Go read a book, clear up, all the words you dont understand and read it from the first page to the last one. As you said you have Petzolds book. Take the examples there and you will see what you are asking for. But the truth is, you are riding the horse from the back. Why you dont start to learn programming trying to write code for Gothic 3 graphics part ?? hm ? :rolleyes: Oh godness :D my dear.Quote:
Originally Posted by dahwan
The gradient you try to learn is much to high. Jumping around in programming techniques is no way to get knowledge about. Its nothing then a bit of Ignorance of how to learn something. Because you cannot understand even the simplest techniques, like how to use the C# IDE and its wizzard to write the few lines of starting code, and you are not able to read the lines the wizzard creates for you and you dont get understanding by duplicating whats going on there, you jump around trying to do some other things.
Believe me - this is the way down the learning curve, instead of upwards. You got more and ore which you cannot understand and at least you will loose fun on programming. Thats the end of the cycle then.
Even I showed you the correct code you still are using main() within a class which is derived from a form. I explained you, why you should not do that and showed you the correct way, I tried to learn you using namespaces but you are ignoring all that.. lets do some other things..
thats not the way to learn it - even when you are 15
And how in the world do you think your Keypress will get into your test Object ? By magic ?? The KeyPressEventArgs which you named aep you havn't used in any line. Why you use the delegate as a static one ? I cannot see to which control you add this delegate ? So if it is not added how should it be called .... Do you think programming works because you are using words like keyboard as the name of your delegate ?Quote:
Originally Posted by dahwan
See my posts before !!
Quote:
Originally Posted by JonnyPoet
Thats what i'm asking... I see no point in declaring a namespace, since there is no point in it. Its a namespace { in the start, and an } in the end. It has no use, and it makes my program bigger. And you explained to me that i shouldn't have the Main() in the same file but you didn't tell me how, so that has no use eighter. :P
And you said that i dont understand the codes the wizard makes for me, which is not true. And you allso said that i copy and paste code i dont understand, which isnt true eighter.:D
What i wondered about was how i can get the keypress into my program, and how do i use it? :D
Wrong it segments names to avoid clashes, you never know where code is going to run into this problem, plan for it from the very beginning.Quote:
Originally Posted by dahwan
Wrong again, it does not add a single byte to your programQuote:
and it makes my program bigger.
By putting it in a separate file, obviouslyQuote:
And you explained to me that i shouldn't have the Main() in the same file but you didn't tell me how,
Have you read HOW to use Viusual Studio???Quote:
so that has no use eighter. :P
The sentance makes no sense. If you Execute KeyPressed and a key is pressed (while your program has focus), then it returns true, else false...Quote:
Now all i asked was how i can get the keypress into my program,
Have you taken the time to read the documentation. If so, what exact sentance(s) did you not understand. Post the url, and the part you did not understand....Quote:
and how do i use it? :D
what documentation...
Start here:Quote:
Originally Posted by dahwan
http://msdn.microsoft.com
Or read the help file....
I have given you the fullcode in the zip I had attaches there you see that main is in the same namespace but not in the class which you derived from the form. So as you still dont use that I have to assume that you didn't really understand all that. Otherwise you would not ask in the way you are asking. we have explaind you whats the sense of namespaces, but you obviously neglect this things. This is no standard ! But if you ever want to get running programs you need to get on standard. Everytime use all what you have learned instead of knowing things and neglecting them.Quote:
Originally Posted by dahwan
Sorry but this is obviously otherwise you would not come with the same errors of former posts again and again.Quote:
Originally Posted by dahwan
I fully agree. This boy is really having misunderstoods in documentation, or he never has read it.Quote:
Originally Posted by TheCPUWizard
Hey Poet!
In despite of my so called "ignorance", i am actully reading carefully everything you guys say. I managed to split my cs files into as many files i want, and the secret was to have a namespace with the same name in all the cs files. (thx Poet :D)
but i am facing an old problem i never got the ansver to:
how do i access my object properties remotely?
i have a keyPressEvent and i want to add text to the textbox when i click ctrl+p. I thought it wasnt possible untill i (by misstake) suddenly changed the form title every time i pressed ctrl+P, lol. So i know its possible, but what ever i write, i get the error "The name txtbox1 does not exist in the current context"
What do i do wrong?
// Main() is in another file //Code:using System;
using System.Drawing;
using System.Windows.Forms;
namespace editor
{
public class EditorWindow : Form
{
public EditorWindow()
{
this.Text = "Text editor - no menu"; // The title line text
this.Width *= 2; // Increase the width lenght
TextBox txtbox1 = new TextBox(); // Create the textbox
txtbox1.Parent = this; // Parent the textbox to the form
txtbox1.Text = "Write here"; // Text
txtbox1.Multiline = true; // Allow multilines
txtbox1.Dock = DockStyle.Fill; // Fill window
txtbox1.AcceptsTab = true; // Accept tabs
txtbox1.KeyDown += new KeyEventHandler(KeyPressHandler);
}
void KeyPressHandler(object sender, KeyEventArgs kea)
{
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Control)
{
txtbox1.Text += "Dude";
}
kea.Handled = true;
}
}
}
Well done. Great :DQuote:
Originally Posted by dahwan
Its an old problem I posted in former posts for you. You need to clarify 'Lifetime of a Variable, a Field, an Object. What means Global, whats the sense of words like private, public, ... internal, proteced and what has this to do with accessing classes, fields, properties.. form outside or inside a class, a library... How to get access to public properties in another namespace, all that things. What is meant with lifetime ? If you clear up this things carefully then you will no longer have such problems as you just have.Quote:
Originally Posted by dahwan
Thats all for thatCode:using System;
using System.Drawing;
using System.Windows.Forms;
namespace editor
{
public class EditorWindow : Form
{
private TextBox txtbox1 = null; // here we prepare a storageplace so we declare a Field
// for the TextBox Control, so it is visible in the whole class, and because
// of 'private' its only visible in the class
// Its lifetime is the same as the class lifes.
// It can be accessed from any method within this class
// but not from outside this class.
//So programming the class you can find this fIELD IN YOUR INTELLISENSE help, as soon as you have declared it here.
public EditorWindow()
{
this.Text = "Text editor - no menu"; // The title line text
this.Width *= 2; // Increase the width lenght
//TextBox txtbox1 = new TextBox(); // Create the textbox
//But if you declare it here then its lifetime is only as long as the
//ConstructorMethod is called. When the method is finished,
// all Fields and objects declared herin are destroyed again
// as they are only created on the stack
// Clarify the words stack and heap storagespace !!!
// as you have declared the txtbox1 as an adress to hold a textbox
// you can Create the textBox object here
txtbox1 = new TextBox(); // Create the textbox
// now its no longer null txtbox1 now holds a textbox
// which can be accessed from everywhere in this class
txtbox1.Parent = this; // Parent the textbox to the form
txtbox1.Text = "Write here"; // Text
txtbox1.Multiline = true; // Allow multilines
txtbox1.Dock = DockStyle.Fill; // Fill window
txtbox1.AcceptsTab = true; // Accept tabs
txtbox1.KeyDown += new KeyEventHandler(KeyPressHandler);
}
void KeyPressHandler(object sender, KeyEventArgs kea)
{
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Control)
{
txtbox1.Text += "Dude";
}
kea.Handled = true;
}
}
}
wow, thanks a lot! I havent tried it yet, but i'll do it as soon as possible. I'll get back to you ;-)
Yeah it worked!!! Allthough, how do i get rid of the DIING every time i press ctrl+p or alt+p?
Are you talking about the Beep ?Quote:
Originally Posted by dahwan
thats it :D How do i get rid of it?Quote:
Originally Posted by JonnyPoet
NEW PROOOBLEM:::
this compiles, but gives errors at startup. Whats wrong with it?Code:using System;
using System.Drawing;
using System.Windows.Forms;
namespace editor
{
public class EditorWindow : Form
{
private TextBox txtbox1 = null;
private MenuStrip menu = null;
private ToolStripMenuItem file = null;
private ToolStripMenuItem exit = null;
public EditorWindow()
{
this.Text = "Text editor - no menu"; // The title line text
this.Width *= 2; // Increase the width lenght
this.MainMenuStrip = menu;
this.Controls.Add(menu);
txtbox1 = new TextBox(); // Create the textbox
txtbox1.Parent = this; // Parent the textbox to the form
txtbox1.Text = "Write here"; // Text
txtbox1.Multiline = true; // Allow multilines
txtbox1.Dock = DockStyle.Fill; // Fill window
txtbox1.AcceptsTab = true; // Accept tabs
txtbox1.KeyDown += new KeyEventHandler(KeyPressHandler);
menu = new MenuStrip();
menu.Items.AddRange(new ToolStripItem[] { file });
menu.BackColor = Color.DarkGray;
menu.Dock = DockStyle.Top;
menu.Parent = this;
menu.Name = "Menu";
menu.Text = "Menu";
file = new ToolStripMenuItem();
file.DropDownItems.AddRange(new ToolStripItem[] { exit });
file.AutoSize = true;
file.Name = "File";
file.Text = "File";
exit = new ToolStripMenuItem();
exit.Name = "Exit";
exit.Text = "Exit";
exit.AutoSize = true;
}
void KeyPressHandler(object sender, KeyEventArgs kea)
{
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Control)
{
txtbox1.Text += " Ctrl+P,";
}
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Alt)
{
txtbox1.Text += " Alt+P,";
}
kea.Handled = true;
}
}
}
Plese give exact data, which error occurs in which line. ( what exception exactly is it ?Quote:
this compiles, but gives errors at startup. Whats wrong with it?
hmm.. suddenly its working when i started declaring the menuitems at the top of the class. Anyway, new problem. I have a menu strip and a fill-docked textbox. The menu overlaps the textbox, so the start of the text appears under the menu line. How do i avoid that?
(textbox is docked at fill, menu at top)
problem fixed by deleting two lines under the width-increasing line, lol.
problems fixed all the time. I spend waay to much time coding...
newest prob:
how can i make my RichTextBox accept backspace? I cant actually delete anything in my RichTextBox, i can yust select a bunch of letters and replace them. Thats a lot of work...
another **** problem:
mainWindow.cs
aboutWindow.csCode:using System;
using System.Drawing;
using System.Windows.Forms;
namespace editor
{
public class EditorWindow : Form
{
private aboutWindow abtWndw = null; // Aboutwindow
private RichTextBox txtbox1 = null; // Textbox
private MenuStrip menu = null; // MENU
private ToolStripMenuItem file = null; // FILE
private ToolStripMenuItem ny = null; // FILE -> new
private ToolStripMenuItem exit = null; // FILE -> exit
private ToolStripMenuItem help = null; // HELP
private ToolStripMenuItem about = null; // HELP -> about
public EditorWindow()
{
/****************************** CREATING OBJECTS ******************************/
txtbox1 = new RichTextBox(); // Creating the RichTextBox
menu = new MenuStrip(); // Creating the Menu Strip
file = new ToolStripMenuItem(); // Creating the FILE menu
ny = new ToolStripMenuItem(); // Creating the FILE sub-menu item "new"
exit = new ToolStripMenuItem(); // Creating the FILE sub-menu item "exit"
help = new ToolStripMenuItem(); // Creating the HELP menu
about = new ToolStripMenuItem(); // Creating the HELP sub-menu item "about"
/****************************** /CREATING OBJECTS ******************************/
/****************************** CREATING THE WINDOW ******************************/
this.Text = "DahWan WebSlinger"; // The title line text
this.Width *= 3; // Increase the width size
this.Height *= 2; // Increase the lenght size
/****************************** /CREATING THE WINDOW ******************************/
/****************************** CREATING THE TEXTBOX ******************************/
txtbox1 = new RichTextBox(); // Create the textbox
txtbox1.Parent = this; // Parent the textbox to the form
txtbox1.Text = "Write here"; // Text
txtbox1.Dock = DockStyle.Fill; // Fill window
txtbox1.AcceptsTab = true; // Accept tabs
txtbox1.ReadOnly = false;
txtbox1.KeyDown += new KeyEventHandler(KeyPressHandler);
/****************************** /CREATING THE TEXTBOX ******************************/
/****************************** MENU ATTRIBUTES ******************************/
menu.Items.AddRange(new ToolStripItem[] {
file, help });
menu.Location = new Point(0, 0);
menu.BackColor = Color.DarkGray;
menu.Dock = DockStyle.Top;
menu.Parent = this;
menu.Name = "Menu";
menu.Text = "Menu";
file.DropDownItems.AddRange(new ToolStripItem[] { ny, exit });
file.AutoSize = true;
file.Name = "File";
file.Text = "File";
ny.AutoSize = true;
ny.Name = "New";
ny.Text = "New";
exit.AutoSize = true;
exit.Name = "Exit";
exit.Text = "Exit";
exit.Click += new EventHandler(exit_Click);
help.DropDownItems.AddRange(new ToolStripItem[] { about });
help.AutoSize = true;
help.Name = "Help";
help.Text = "Help";
about.AutoSize = true;
about.Name = "About";
about.Text = "About";
about.Click += new EventHandler(about_Click);
/****************************** /MENU ATTRIBUTES ******************************/
}
/****************************** HANDELING CLICK EVENTS ******************************/
void exit_Click(object sender, EventArgs exit)
{
Close();
}
void about_Click(object sender, EventArgs about)
{
abtWndw = new aboutWindow();
abtWndw.Show();
}
/****************************** /HANDELING CLICK EVENTS ******************************/
/****************************** HANDELING KEY-DOWN EVENTS ******************************/
void KeyPressHandler(object sender, KeyEventArgs kea)
{
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Control)
{
txtbox1.Text += " Ctrl+P,";
}
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Alt)
{
txtbox1.Text += " Alt+P,";
}
kea.Handled = true;
}
/****************************** /HANDELING KEY-DOWN EVENTS ******************************/
}
}
Compiles successfully, gives **** error at the click of menuItem "about".Code:using System;
using System.Windows.Forms;
namespace editor
{
class aboutWindow: Form
{
private TabControl tabCtrl = null;
private TabPage tabPge1 = null;
private TabPage tabPge2 = null;
public aboutWindow()
{
this.Text = "About WebSlinger";
this.Width /= 2;
this.Height /= 2;
tabCtrl = new TabControl();
tabCtrl.Controls.Add(tabPge1);
tabCtrl.Controls.Add(tabPge2);
tabCtrl.Dock = DockStyle.Fill;
tabPge1 = new TabPage();
tabPge2 = new TabPage();
}
}
}
WHYCode:Unhandled exeption has occured in your application.
Here you have your problem
Code:...
public aboutWindow()
{
this.Text = "About WebSlinger";
this.Width /= 2;
this.Height /= 2;
tabCtrl = new TabControl();
//You need to insert the Create tabPge1 and tabPge2 here !!!!!!!
// add this lines here
tabPge1 = new TabPage();
tabPge2 = new TabPage();
tabCtrl.Controls.Add(tabPge1); // here you add a control which is not created at that time ( = null)
tabCtrl.Controls.Add(tabPge2);// here you add a control which is not created at that time ( = null)
tabCtrl.Dock = DockStyle.Fill;
// Here you create the controls but this is to late
//tabPge1 = new TabPage(); // remove this here
//tabPge2 = new TabPage();
// In the end you need to add the Tabctrl to the Forms Controls Collection
// other wise you will not see it
this.Controls.Add(tabCtrl);
}
Thats only a problem of your codeQuote:
Originally Posted by dahwan
This is wrong as you tell in any case that the keypress is handled so the key is eaten up ( all further effects which would normally being caused by a key are cancled. )Code:/****************************** HANDELING KEY-DOWN EVENTS ******************************/
void KeyPressHandler(object sender, KeyEventArgs kea)
{
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Control)
{
txtbox1.Text += " Ctrl+P,";
}
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Alt)
{
txtbox1.Text += " Alt+P,";
}
kea.Handled = true;
}
You need to do this in a way like that
This handles your troubles.Code:void KeyPressHandler(object sender, KeyEventArgs kea)
{
bool eatIt = false;
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Control)
{
txtbox1.Text += " Ctrl+P,";
eatIt = true;
}
if (kea.KeyCode == Keys.P && kea.Modifiers == Keys.Alt)
{
txtbox1.Text += " Alt+P,";
eatIt = true;
}
kea.Handled =eatIt;
}
Thx!!!
Does anyone know anything about icons? all the icons on my computer looks really fancy and stuff, but when i wana make my own, i am maxed out on 16 colors!!! allso, when i compile my window, all the icons are still the same, no matter what icon i've drawn. Allso icons (in explorer) has diffrent sizes depending on where they are and stuff, does this mean i need several diffrent icons etc? if anyone know about a good tutorial explaining that, i'd be gratefull :D
Or if someone knows anything about it and can explain it here :)
i am searching myself too.
There are 1000 tds of ´free iconlibraries in the web.But if you want to draw your own then use Microangelo which is 30 days free trial and really cheap. ( I use this ) Then you have tools for winowsstyled colors and all that you need to do great icons. In your Petzolld book I think there are examples how to implement icons by code.Quote:
Originally Posted by dahwan
ok, i figured out the color thing. What the problem is now is that i cant attach the icon to the form:
i have the icon "mainIcon.ico" in the same directory as the .cs file if that helps....Code:this.Icon = new Icon( no idea what to put here );
oh, i didn't see your last post untill now, Poet. I'll check the book, and get back to you if it doesnt help =)
ok, i managed to get the icon into the file and compile it. The problem is that the icon is only displayed in explorer when i am viewing icons in 32x32. But the top left corner of my form has a litle picture of a piece of paper, and not my icon. So my idea is that i need several icon files. one of them in 32x32 and one smaller. But how do i approach this?
Plz help, Poet :D
If you have Icons 32x32 and you want to show them e.g. in the toolstrip in a size of 16x16 then doQuote:
Originally Posted by dahwan
In this case I have my pictures in the resources File and the picture is named myPicture1Code:this.toolStripButton2.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.toolStripButton2.Image = global::WindowsApplication1.Properties.Resources.myPicture1;
this.toolStripButton2.ImageScaling = System.Windows.Forms.ToolStripItemImageScaling.SizeToFit;
Using ImageScaling as SizeToFit you will have 16x16 pictures and if you have None then you will get 32x32 as this is the original size of the image. thats the easiest way to do it.
PS.: :D Isn't your Icon ( 1 kow C# ) a bit toooo arrogant ?:p :rolleyes: :D
oh, is it arrogant? sorry, my english kinda sucks. i`ll change it if you want.
i found out about the icons. thanks for the help.
ps. i am on vacation at the mountain. took me days untill i realised i could use my phone with 3G.
i will get it connected to my PC before i post up my next prob =D
(writing with this is fun :D)
I was joking :D oh god :rolleyes: thats all about :DQuote:
Originally Posted by dahwan
oh, ok ^^
OK, problem, live from Norway:
I am having thread problems. In my wysiwyg editor, i want to preview the internet page in my editor, so i have a "run" button. When i click it, i save a temporary html file with richtxtbox1.Text in it. When its run, it shows:
System.Windows.Forms.RichTextBox, Text: //content
how do i get rid of the "System.Windows.Forms.RichTextBox, Text:" ?
second problem: i wanted to display the page IN my editor, so i made a webBrowser window. Now, this compiles fiiine, but it errors and babbles about threads when i click "run". run is suposed to pop up a new window with a webBrowser in it.
It sais that activeX control cannot run because current thread is not in a STA. I have allso tried to make a new thread and run the window in it, but threads is not one of my strong sides (if i at all have any strong sides), and i need help with it.
how do i make this work?Code:using System;
using System.IO;
using System.Xml;
using System.Drawing;
using System.Threading;
using System.Collections;
using System.Diagnostics;
using System.Windows.Forms;
using WebSlinger.Properties;
using System.Text.RegularExpressions;
namespace editor
{
class testRunWindow : Form
{
private WebBrowser browserWindow;
public testRunWindow()
{
//
//
//TestRun window
this.Text = "Options"; //titlebar text
this.Width /= 2; //width
this.Height /= 2; //height
//
//
//Browser window
browserWindow = new WebBrowser();
browserWindow.Dock = DockStyle.Fill; //dock
browserWindow.Parent = this; //parent
browserWindow.Url = new Uri("http://www.google.com"); //adress
}
}
}
Re STA Thread If you look into one of my examples where I showed you to separate Main from the Form you see the solution
Here you declare the thread to be STAThread ( SingleThreadedApplication )Code:static class Program
{
[STAThread]
static void Main()
.....
Another small point to correct your coding style: The following you can really learn from looking how the wizzard does
private fields begins with small letters but Classnames, Namespaces Functions, Properties everytime begins with big letters so we have
namespace Editor, class TestRunWindow .... Please accept this and correct your coding Style this way
thanks, i'll try this
btw, i think its "single threaded apartment"
Yes, I think you are correct. Thats one of this abbreviations where I like to do my own interpretation. :DQuote:
Originally Posted by dahwan
still a problemQuote:
Originally Posted by dahwan
Please show full code Best way zip itQuote:
Originally Posted by dahwan
good possibility is that ".ToString()" is being called on the control.... ;)
?Quote:
Originally Posted by TheCPUWizard
as you wishQuote:
Originally Posted by JonnyPoet
actually, i now changed from opening it in IE to displaying it in my window. And now the window is actually white; whatever i have written in my txtbox.
why?
i discovered that if i right-click my browser window and choose "display source code", i get "System.Windows.Forms.RichTextBox, Text: 12345" (the content of txtBix1 being "12345")
how do i get rid of the "System.Windows.Forms.RichTextBox, Text:", and how do i display anything in the browser window?
Looked through the code you posted (please use zip, not rar files in the future, many here do not have WinRAR or equivilant so you end up limiting yourself...)Quote:
Originally Posted by dahwan
I did not see any reference to "richtxtbox1" in the code (there are references to "txtbox1")... :confused: :confused:
My previous post was related to the fact that the default implementation of "ToString()" (which is supported by EVERY object, is to return the type name as a string..
Thx for posting your code
There are some probems with it easy to handle
a) USE ZIP instead of RAR files
b) The Resources are missing
c) Never use Pathes in your Program no other one will be able to use it as he doesnt have the same pathes as you have so e.g. all your pictures needs to be in the resources File
d) Use the satndard IDE and the standsard project files so nobody needs to rearrange all your project files and to have extra work for arranging them and creating a project file first.
Sorry I myself have no experience with html so I cannot answer your question. Your request was unclear for me, as I thought you are using a normal richtextbox anywhere in the program and you get an errormessage, but now you drescribed better and I can verify your problem, but here you ned some advice from a programmer with web experience.
you don't need no friggin web experience. i just wana know why i dont get all the text in the rich text box when i save its content to a file. ANY file. in my case html, but allso .txt files, and even .argawriu files.
Sorry your code is totally confusing. As you are not using the satndard way of deviding in Partial Classes using a designer, the self written design is mixed up to normal codepages and the events normally added to the forms code where they are done is in a separate document ??? As I said in all posts before. GET ON STANDARDQuote:
Originally Posted by dahwan
LEARN TO USE AND UNDERSTAND DESIGNER !
You have e.g created a new richtextbox as Textbox1 twice in your program, you have created an XML document, but you never use it, ?
So delete the second one
You are telling that you are using a namespaceCode:/****************************** CREATING THE TEXTBOX ******************************/
//txtbox1 = new RichTextBox(); // Create the textbox // NO ITS DONE BEFORE IN Your CONSTRUCTOR ( You did it there too )
txtbox1.BackColor = Color.LightGray;
in every document but I have non of such namespace anywhere. Where it is, where are the missing resources ?Code:using WebSlinger.Properties;
...
Streamreader and Streamwriter are Resources which are normally opend, used and instantly closed and disposed So why you do them as private fields. Here you have a typical misunderstood again of how to use lifetime of fields, objects... When you only need to read or store data then you only declare the reader and writer in the method they are used and then closing and finished.
Otherwise in your program try to save any text then open it again and then change it and try to store again. You will fail and get error that you cannot do as the file is used by another. Its still in use by your open still reader, so you cannot rewrite again to him
So please in every Event / Method what else, where you have a StreamReader or a SteamWriter do like that
Delete the following Fields in your EditorWindow classCode:// Use local Objects only instead of private fields
StreamWriter SW = File.CreateText(saveResult.FileName);
SW.Write(txtbox1.Text);
SW.Close(); // add this to close the Resoure
You cannot keep them open all over the time the program runs and the EditorWindow is your mainwindowCode://private StreamReader SR;
//private StreamWriter SW;
Additional: If you have an editorwindow and a new Page is added then it normally has to turn to a white Background,otherwise who should know that he is allowed to type to a dark backgroundimage ?
Also in that way use the STANDARDS which are used in e.g.WORD, PDF.s ... How a user should work with it. He is awaiting usage as he knows from other programs. :mad:
Jonny,
Good comments...Except the following is much better:
Note that you do not need to explicitly close the SW, and that this code is 100% reliable in the event of exceptions.Code:// Use local Objects only instead of private fields
using (StreamWriter SW = File.CreateText(saveResult.FileName))
{
SW.Write(txtbox1.Text);
}
Yes thx a lot, for mentioning that. As you know I'm just learning C# too... but :blush: I had studies this .. so I should have known ( end of blush):DQuote:
Originally Posted by TheCPUWizard
Yea, I was only going about his code, a bit going crazy about permanent out standard problems not only regarding coding, also in run time habits. e.g. you start the program you get an MDI looking interface with a gray background. If you use 'Menue-> New' nothing happens. I was looking around for about 15 minutes studying his code what and where he would have an editorwindow. Then I found out - its there from the beginning but gray all the time just as the background of an MDI when no child is activated.. oh goodness. Hihi
But I havn't known that using 'using' doesn't need to close it at the end. Must have overseen this, need to have a look into my book again. :thumb: