|
thank you a lot. but how about panel ? when I add a panel to the parent form,child form goes behind panel.
|
|
|
|
|
There is a property called BringToFront() .
Try using this property on your child control.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
I tested it but it didn't work.
|
|
|
|
|
I ran into this issue myself, you have to dock your panel to get the behavior you want.
|
|
|
|
|
how? I already start to learn c# and I don't know what you mean.
|
|
|
|
|
My apologies for the relatively newbie-ish question -- I'm rather new to C# and WPF programming. Here's an object I'm trying to use with strong influence from Pro WPF in C# 2008 (.NET version 3.5) that's supposed to validate a text box's contents:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
namespace LeanQualityTool
{
public class ValidatedTextBox : TextBox, INotifyPropertyChanged, IDataErrorInfo
{
private string _TextContents = "";
public string TextContents
{
get { return _TextContents; }
set { _TextContents = value;
NotifyPropertyChanged("TextContents");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
#region IDataErrorInfo Members
public string Error
{
get { return null; }
}
public string this[string fieldName]
{
get
{
string result = null;
#region For Validating Text
if (fieldName.Contains("Title"))
{
if (this._TextContents.Length == 0)
{
result = "Text should not be blank";
throw new ArgumentException(result);
}
else
{
}
}
#endregion
return result;
}
#endregion
}
}
}
And here's the relevant XAML:
xmlns:vip="clr-namespace:LeanQualityTool"
<vip:ValidatedTextBox Height="23" x:Name="txtJobTitle" HorizontalAlignment="Left" Width="276"
Style="{StaticResource validatedTextBox}">
<TextBox.Text>
<Binding Path="SelectedItem.Title" UpdateSourceTrigger="PropertyChanged"
ValidatesOnDataErrors="True">
</Binding>
</TextBox.Text>
</vip:ValidatedTextBox>
I try to put a breakpoint on the IF statement in the class, but when I debug the app, changing the text in the textbox doesn't even cause the breakpoint to engage. Why isn't the new ValidatedTextBox working?
|
|
|
|
|
Try posting this in the WPF forum. You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
|
Did you really get this code from book? I really need to write a book.
BTW, you are binding to the Text property of the TextField. In code and not automagic binding, what kind of happens is this:
public class TextBox{
public string this[string fieldName]{
get;
set;
}
}
TextBox foo = new TextBox();
foo.Text = "Some Value";
So the Text Property is getting fired. Your codes seems to be:
public class TextBox{
public string Text{
get{...}
set{...}
}
}
TextBox foo = new TextBox();
foo["test"] = "test";
What I think the Author meant was, register the Notify Property event changed from the parent Text Box then call your validate method which should be a method and not an indexor like:
public class TextBox : System.Windows.Forms.TextBox {
protected override void OnTextChanged(EventArgs e) {
base.OnTextChanged(e);
Validate();
}
public void Validate() {
}
}
Of course I am just guessing.
|
|
|
|
|
Worked like a charm!
Let me know if and when you get that book written, okay? I'll buy three copies.
|
|
|
|
|
I have an application which a tabcontrol on it. Each tab has various input boxes of various types (textboxes, gridviews, checkboxes and comboboxes). When the user clicks a tab the applicable data is loaded from a database and the controls on that tab are populated. When the user clicks a different tab, a messagebox should pop up asking if he wants to save his input. That part is not a problem. However, I would only like the box to pop up if he changed any input, or at least clicked inside a control. Is there a global way to sense this? I thought about creating a boolean flag, that gets set in each control change event - however this would seem bulky.
Thanks
Marc
|
|
|
|
|
If you already have a class that holds the data for each page, then you can take a copy of the original data and then compare it to the possibly edited data.
It's a bit of work to implement a copy constructor and equality operator, but it does have the advantage that if a user changes something and then changes it back, then he won't be prompted to save.
Nick----------------------------------
Be excellent to each other
|
|
|
|
|
What do you mean a class that holds the data? I guess I could put the data in a dataadapter object, and then load the data into a second dataadapter object upon tab click and compare the two objects. Not sure if you can compare them directly though.
Thanks
Marc
|
|
|
|
|
mbangh wrote: What do you mean a class that holds the data?
The states of your controls, for example the Text property of a TextBox control, represent data. You must be storing this data somewhere. You normally store it in an instance of a class, for example an instance of a Person class that has string properties that hold a particular person's first and last names.
When you load a form, you normally take data from your object and set the states of your controls. The user then has the opportunity to alter the controls. Then you put the new data back into your object to persist it.
If this is the case, then I was suggesting comparing the before and after objects instead of trying to detect when a user manipulates any control.
Nick----------------------------------
Be excellent to each other
|
|
|
|
|
Add a notify property changed event to the underlying data object. Register the event listener on the DataAdapter. If the event gets fired, show your message box. Otherwise, don't.
|
|
|
|
|
Hi there
I can't get Exchange webservice for Exchange 2007 SP1 working
http://msdn.microsoft.com/en-us/library/bb408417%28EXCHG.80%29.aspx[^]
when I run the following C# code:
ExchangeService service = new ExchangeService();
service.Credentials = new WebCredentials(@"username", "password", "domain");
service.AutodiscoverUrl("username@domain.co.za");
FindItemsResults<Item> findResults =
service.FindItems(WellKnownFolderName.Inbox,new ItemView(10));
foreach (Item item in findResults.Items)
{
}
It get this error:
Request failed. The remote server returned an error: (401) Unauthorized.
Any help will be greatly appreciate !!
Thanks in advance.
|
|
|
|
|
hello, can anyone help me with this?
|
|
|
|
|
Hi
I have a dialog form that has validation in it. If things are invalid, another window appears with the list of errors that they can double click on and be taken to the point of the error.
What I would like to do is not have this error window appear in the taskbar and have the window appear when the main dialog regains focus.
I've looked arround and tried this
private void Form1_Activated(object sender, EventArgs e)
{
if (newErrorForm != null)
{
newErrorForm.BringToFront();
this.Focus();
}
}
but this causes the error window to always have focus even though I'm shifting it back to the main form. Is there a way to achieve this?
Many ThanksThe FoZ
|
|
|
|
|
TheFoZ wrote: What I would like to do is not have this error window appear in the taskbar
There's an option "ShowInTaskbar" that stops that.
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
Now reading: 'The Third Reich', by Michael Burleigh
|
|
|
|
|
I know, that is what's causing the problem. To only way to get the form back is to minimise the windows until you find it again. I just want the user to click on the dialogs button in the task bar and both windows appear. The FoZ
|
|
|
|
|
I'm making changes to a file, saving the edits to a StringBuilder, then writing the mods to a temporary file before deleting the original and then renaming the temporary file.
Now, I want to be able to determine what new line character(s) to use for the file being modified.
At the moment if I look at the changes made to a text file from a UNIX machine with WinMerge, it'll show that every line has been modified because of the AppendLine() method of the StringBuilder, which defaults to I'm guessing "\r\n" where UNIX uses "\n".
"That's fine, I'll just use Append(..) then Append("\n")..." I thought.
But then WinMerge will highlight the same issue for Windows based text files that require "\r\n".
Currently I use a StreamReader.ReadLine() to whip through each line of the file, but that just consumes the EOL characters so I can't determine it that way.
Do I really have to Peek() through the file until I come accross the "\n" or "\r\n",
or is there a smarter way to do it?
Thanks y'all.
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
Now reading: 'The Third Reich', by Michael Burleigh
|
|
|
|
|
Hi,
here are some facts that should help you out:
- Environment.NewLine (read-only) holds the line terminator used on your system; you can't change it;
- StringBuilder.AppendLine relies on Environment.NewLine;
- TextWriter is an output text stream that has a NewLine property, which you can set;
- TextReader is an input text stream that is tolerant to all kinds of line terminators (but doesn't tell you which ones it sees).
So you probably should read your file with TextReader, write the new one with TextWriter, and not just rely on StringBuilder. AFAIK the text streams are buffered, so going through a StringBuilder isn't paying off, just do TextWriter.Write instead of StringBuilder.Append
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Hhmmmmmmm...interesting.
Thanks Luc, I shall look at the TextReader/Writer classes and see what I can find.
The main thing I'm trying to do is just to find out what EOL terminator the file is using,
and then use the same again for the 'modified' file.
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
Now reading: 'The Third Reich', by Michael Burleigh
|
|
|
|
|
OK, been there. First read (part of) the file in binary, looking for \n and \r, and make up your mind. Then start using TextReader and TextWriter.
BTW: what if the input file's NewLine is inconsistent?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.
|
|
|
|
|
Luc Pattyn wrote: BTW: what if the input file's NewLine is inconsistent?
Then...I start to cry.
As I would have to go through each line, then look for the appropriate EOL terminators,
then use that EOL for the modified file.
I thought this would be easy!
Where are those tissues...
"If you can't explain it simply, you don't understand it well enough" ~ Albert Einstein
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." ~ Paul Neal "Red" Adair
Now reading: 'The Third Reich', by Michael Burleigh
|
|
|
|