473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How can I stop a form from closing & wordrap a singline

I'de like to ask users if they are able to save their work before they
close using the normal "Save? Yes, No, Cancel" type of message box.

I've got this so far:

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if(unSaved)
{
DialogResult result = MessageBox.Show("Do you want to save
the changes you made to" +
Path.GetFileName(currentFilePath) + "?", "Save
Changes?", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation);
if(result==DialogResult.Yes)
saveFile(currentFilePath);
if(result==DialogResult.Cancel)
{
}
if(result==DialogResult.No)
{
}
}
}
}
What can I put in the result==DialogResult.Cancel if statement to
cancel the closing process?

Also, I'de like to have a textbox that wordraps a single line of text
so it can be short in width but a bit longer in height and still be
able to show a large string because of wordwrap. I would basically
like to have a multiline textbox with wordwrap on without allowing
users to insert new lines in the text box. Too bad wordwrap does not
work when multiline is false.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #1
7 1496
Hi supster,

You only lack 1 line. In the "if cancel" put

e.Cancel = true;

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
Oh yeah, and for the wordwrap textbox. Set MultiLine and ReadOnly. Then set BackColor to SystemColors.Window or some other color of choice, or leave the disabled color as it is.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #3
Hi!

Morten Wennevik wrote:
Oh yeah, and for the wordwrap textbox. Set MultiLine and ReadOnly. Then

set BackColor to > SystemColors.Window or some other color of choice, or
leave the disabled color as it is.

Doesn't that make the textBox readOnly ? I needed a similar textBox some
time ago and worked it out like this:

========== C#-CODE ==========

private bool internalAction = false;

private void InitializeComponent()
{
//...
// Hook up the event for TextChanged
this.textBox1.TextChanged += new
System.EventHandler(this.textBox1_TextChanged);
//...
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
// Get CursorPosition
int position = ((TextBox)sender).SelectionStart;

// Check if change event was fired from typing in textBox
if (!this.internalAction == true)
{
// Get the current Text
string text = ((TextBox)sender).Text;
// Find position of <return>
long index = text.IndexOf("\r\n");
if (index > -1)
{
// We will remove two characters from text, so check
// if cursor position has to be changed
if (index <= position)
{
position = position - 2;
};
// Remove "/r/n" from text, making sure
// this method will not execute twice
this.internalAction = true;
((TextBox)sender).Text = text.Replace("\r\n", "");
this.internalAction = false;
}
}
// Reset cursor position
((TextBox)sender).SelectionStart = position;
}
Nov 16 '05 #4
On Wed, 9 Jun 2004 12:55:39 +0200, Michael Voss <mi**********@lvrREMOVE.deCAPS> wrote:
Hi!

Morten Wennevik wrote:
Oh yeah, and for the wordwrap textbox. Set MultiLine and ReadOnly. Then

set BackColor to > SystemColors.Window or some other color of choice, or
leave the disabled color as it is.

Doesn't that make the textBox readOnly ? I needed a similar textBox some
time ago and worked it out like this:


Yes, it will make the TextBox readonly ( Setting ReadOnly usually does :P ), but that was what he wanted.
"I would basically like to have a multiline textbox with wordwrap on without allowing users to insert new lines in the text box."

Your code appears to strip line breaks from an input to the textbox, but supster used a single line of string and did not want users to be able to write anything to it.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #5
Thanks for the e.Cancel thing, that helps a lot =)

I actually wanted users to be able to enter input, but just one line.

I tried a similar method Michael, on text change I tried:
textBox.Text = textBox.Text.Replace("\r\n", "")

That didn't work, any other ideas?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #6
Still looking for suggestions for doing the box, anyone?
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 16 '05 #7
Hi !
supster wrote:
I tried a similar method Michael, on text change I tried:
textBox.Text = textBox.Text.Replace("\r\n", "")

That didn't work, any other ideas?


Your above code worked fine for me (although the cursor will not be
positioned correctly); are you using a System.Windows.Forms.TextBox ? Do you
hook up to any other event ?
Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Saradhi | last post by:
Hi, I wanted to stop the VS.NET Window from closing inside my C# AddIn. I Know that OnBeginShutdown() funciton will be called whenever the user tries to close the VS.NET window. I want to...
6
by: John S | last post by:
When the user clicks the "X" in the upper right-hand corner of a form, how can I stop the form from closing?
8
by: Tim_Mac | last post by:
hi, i have a group of individual radio buttons that i am running some client-side code on for the onClick event. there is a URL generated by a code block inside the onClick attribute. the...
1
by: JohnR | last post by:
I have a form that is presented in an mdi child window. If the user hits exit or the X button on the titlebar of the mdi child form, that form's "closing" event fires and in that event I check to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.