here is my problem. i have a RichTexBox with a document in it. after some modifications it needs to be printed. however in the printed version no white spaces must be left from the end of a paragraph to the end of the line. i have tried to adjust the size of the RichTextBox to the size of the paper used by the printer (usualy A4) and set left and right indentation of text (making a copy of the rtf before this in order to print it unindented, otherwise it will just double the indentation) accordingly to printer settings indentation values. however print preview and printed version text differs from the one shown on screen. the text is printed as formated text with justified align and different fonts and sizes, using a control derived from RichTextBox witch has such printing support described here now if anyone has any ideas as to how i can atleast hadle this problem ..
gaby2r
Posts
-
richTextBox print & print preview -
Dpiyou can use the folowing function to make calculations and transformations betwin different coordonating spaces Graphics.TransformPoints
-
MDIwhat it should do (if you change the mdiChild to it's correct name MDIChild) is assign the current form as mdiparrent to the MDIChild form. maybe the names confuse you. here is a better example:
Form P = new Form(); Form C = new Form(); P.IsMdiContainer = true; //alows the form to contain MdiChilds C.MdiParent = P; //states that C is a MdiChild of P P.Show(); C.Show();
bare in mind that once a from is a mdiChild it cannot be a MdiParent as well(as in you can't have a mdi form inside an mdiform). In the above example if you set C.IsMdiContainer = true; an exception will be raised. -
multi threading & progressBar problempublic void task() { Thread.Sleep(9000); } private void button_Click(object sender, System.EventArgs e) { this.progressBar1.Value=0; Thread t=new Thread(new ThreadStart(task)); t.Start(); while((t.ThreadState & (System.Threading.ThreadState.Stopped | System.Threading.ThreadState.Unstarted)) == 0) { if(this.progressBar1.Value==this.progressBar1.Maximum) { this.progressBar1.Value=this.progressBar1.Minimum; } this.progressBar1.PerformStep(); Thread.Sleep(500); } t.Join(); }
works the first time, progressbar progresses nice and neat, never works again. what am i missing here? -
Zooming on winform controlsi hope i understood your question. you can add a Zoom function to your pannel that has a zoom parameter (on a 1 to at least 100, it can be higher since you could zoom to lets say 500%) that will resize the size of your controls and the distance betwin them(theyr location that is). you need to define a scale however for your controls. ofcourse you need to remove the anchor proprietys of all the controls in that panel and for more realism you will need to code a function for resizing the text font of the controls and add it to every control's SizeChange eventHandler.
-
How to resise controls when maximising the C# Application?you can use the Anchor propriety of the controls to a certain degree. For example if you have a control Anchored to a margine, whenever that margine is moved the control will always keep the same distance from that margine. if the control is Anchored to two oposed Margines(left and right for example), when the parent control is resized, the control will increase his size acordingly so as to keep the same distances from the margins(in the left right case he will increase his width). Anchors work in desing mode too .. you should try and experimet with them there. if you want more control you can handle the SizeChanged event of the parent control (this beeing in your case the main form).
-
button click eventyeah that crossed my mind too. but it seems a bit sadistic to me anyways. funny thing is i knew about Application.DoEvents() and actualy used it .. but to no result. in my test i placed it in the while loop because normaly you want from time to time the app to respond to other calls but oddly it didn't work(no idea why thow). the other thing that crossed my mind was to add a messageFilter before thread.Start and remove it after my task finished. but that's a bit too costly in my opinion.
-
button click eventneat! works. thanks for the help
-
button click eventwell for one your example doesn't work. mainly because that's not the propper way to test if a thread is running. however even if i correct that problem it still doesn't solve my problem because now you have to sincronize the started thread. if you will read my third post you'll see a sincronised example that well you guessed it .. doesn't stop the calls.
-
button click eventobviously you haven't payed attention to my first post. the first example does just that. disabling the button and enabling it after the task is done. however it doesn't behave as expected. Visualy the button is disabled, but the function executes as many times as you push the button, regardless of it's state (disabled/enabled). if you put a counter in it and look at it after the test you'll see it's nice and neat the number of clicks you made. i think that this is because somehow it stacks the events and fires them after the function executes. try and run this code:
public void task() { Thread.Sleep(1000); this.counter++; } private void button1_Click(object sender, System.EventArgs e) { this.button1.Enabled=false; Thread t=new Thread(new ThreadStart(task)); t.Start(); while((t.ThreadState & (System.Threading.ThreadState.Stopped | System.Threading.ThreadState.Unstarted)) == 0) { Thread.Sleep(100); } t.Join(); this.button1.Enabled=true; Debug.WriteLine(this.counter); }
this has multi threading too. i can't exclude the possibility i'm doing something wrong but i can't seem to see where. pointers anyone? -
button click eventlets say i have a simple form with a button on it. let button1_Click() be the function binded by the eventhandler delegate. the problem: i need this function to do a certain task that may take some time. i don't want this to freeze the UI(user interface) however i need to stop any further calls to button1_Click() for the duration of the task. sounds realy easy but to my surprise it's not that easy. take the following examples of the button1_Click function bodys:
{ this.button1.Enabled=false; //do task this.button1.Enabled=true; }
visualy disables the button but if you push it (even if disabled) X times the function will execute exactely X times.{ if(this.ignore) return; this.ignore=true; //do task this.ignore=false; }
same as above just that it doesn't visualy disable the button. ideas, solutions and explanations apreciated.