I just found DockPanel Suite and am learning to use it.
I downloaded v2.9 and am using it with C# in VS2013. I created a simple Windows Forms MDI app. It has one type of child form which is a simple form with only a rich text box control in it. I loaded a few of these as documents. I added an icon to the document's tab to indicate whether the rich text box text has been saved or not.
I change the tab icon anytime the user types in the rich text box through the use of the text_Changed event:
private void txtCode_TextChanged(object sender, EventArgs e)
{
//The text has changed, set the warning icon.
this.Icon = MyApp.Properties.Resources.Warning;
}
The problem I have is that the icon does not update when running at full speed. It updates fine when I am single stepping through the above event. It also updates fine when I load a file within the form's Load event;
private void frmCode_Load(object sender, EventArgs e)
{
//Get the full file path.
string sFile = Path.Combine(cCoCoIDE.CodeBaseRootFolder, Path.GetFileNameWithoutExtension(cCoCoIDE.CodeBaseFile), this.Text);
//Load the source file into the code window.
//A few validations.
//Make sure the file exists.
if (File.Exists(sFile))
{
//File is there. Is it empty? Load only if not empty.
if (new FileInfo(sFile).Length > 0)
{
txtCode.LoadFile(sFile);
//I had to add the following because the text changed
//event fires when I load the file and I need to start
//off with the green checkmark icon.
this.Icon = CoCoIDE.Properties.Resources.GreenChk;
}
}
}
I tried the following after I change the icon (in the Text Changed event):
this.ShowIcon = true;
this.Refresh();
this.Update();
Note: I tried these one at a time. The above is just a list of methods.
Can anyone help me with this? Thank you! SgarciaV
I found the solution. See here:
Dockpanel Suite: Image not updating
Related
I'm developing a WPF application. I will do a drag and drop in this app but I need to get the file's name(or path) when dragging the file(without dropping). I think this may related to some shell programming. Does anyone know how to realize it?
What do you mean by 'get the file name when dragging a file'? Are you asking how to automatically copy the name of a file when you drag it into your WPF application?
To get the file name:
Try clicking once on the file icon, then click again on the file's name about 2-3 sec later. The name will become an editable text field and you can Copy the name before dragging, to be pasted into the WPF application.
To get the file path:
In Windows Explorer (file browser), browse to the file you want to drag. In the bar at the top of the window where it shows the folders you've gone through, right-click and select "Copy address as text". You can then Ctrl+V the filepath into any text field.
It's kind of hard to understand what you're asking (kind of tired here), sorry if my answer didn't help in the slightest haha.
private void MyControl_DragOver(object sender, DragEventArgs e) {
e.Effects = DragDropEffects.None;
if (e.Data.GetDataPresent(DataFormats.FileDrop)) {
string[] paths = e.Data.GetData(DataFormats.FileDrop) as string[];
if(paths.Lenght > 0 && File.Exists(paths[0])) { // <- example, you must handle it in your way
e.Effects = DragDropEffects.Copy | DragDropEffects.Move;
}
}
}
I have a program written in c# that contains a listbox with an observable collection. I want a balloon to pop-up for the user (in the system tray) when the collection has an item added. I have a class that contains a method for notifying the listbox when an item is added (see below):
void OnFileCreated(object sender, FileSystemEventArgs e)
{
if (!base.Dispatcher.CheckAccess())
{
base.Dispatcher.BeginInvoke(
DispatcherPriority.Normal,
(FileSystemEventHandler)OnFileCreated,
sender, e);
}
else
{
// Ignore new directories.
if (File.Exists(e.FullPath))
{
Debug.WriteLine("File Created: " + e.FullPath);
_files.Add(new ObservableFileInfo(e.FullPath));
//Alert users to new request
string title = "Access Request";
string text = "A new access request has been submitted";
//show balloon with built-in icon
tbi.ShowBalloonTip(title, text, BalloonIcon.Error);
}
}
}
The code works exactly as intended apart from the fact that the balloon will only show if I create a new instance of the balloon within the OnFileCreated method (not seen above as I took the code out). For reference, I am using the system tray icon .dll from the following project: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon?fid=1540774&select=4624878&fr=51#xx0xx
My issue is that I already have a system tray icon initiated in the MainWindow class, but I cannot call on it to show a balloon from my OnFileCreated method. I am not sure how I can "share" this information across classes.
If anyone has any ideas that would be great.
I ended up using FindResource to locate the resource defined in the xaml resource document. This was specified in the project code I was referencing to, however FindResource was not working by itself, I needed to add App.Current:
notifyIcon = (TaskbarIcon)App.Current.FindResource("NotifyIcon");
notifyIcon.ShowBalloonTip(title, text, BalloonIcon.Error);
I have a C# winForm project that uses a ContextMenuStrip. I dynamically add ToolStripMenuItems to the ContextMenuStrip based on use interaction. When I add a new ToolStripMenuItem I set it's Text property and Image property. I don't know how to the set the Image property without getting the image from the location where it's at. How do I add the imagine to my project? Here's an example of what my code is doing
ContextMenuStrip cxtMnuStrp = new ContextMenuStrip;
private void Button_Click(object sender, EventArgs e)
{
// some filtering and logic
// to determine weather to
// create and add a ToolStripMenuItem
// blah, blah, blah...
ToolStripMenuItem item = new ToolStripMenuItem("uniqueName");
item.Image = Image.FromFile(#"C:\MyFolder\MyIcon.ico");
if (cxtMnuStrp.Items.ContainsKey(item) == false)
cxtMnuStrp.Items.Add(item);
}
With "item.Image = Image.FromFile(#"C:\MyFolder\MyIcon.ico")" When I distribute my each machine would have to have the "C:\MyFoler" directory and also have the "MyIcon.ico" on their computer in the "C:\MyFoler" directory.
Plus it doesn't seem right that I have hit the hard drive each time I want to add an icon to my ToolStripMenuItem
You could save your icons in a resource file or save the image as a embedded resource.
Using the resource file.
Adding and Editing Resources (Visual C#)
Adding the images as a embedded resource
Visual Studio: How to store an image resource as an Embedded Resource?
You code will will be as shown below.
private void BuildContextMenuStrip_Click(object sender, EventArgs e)
{
ContextMenuStrip cxtMnuStrp = new ContextMenuStrip();
ToolStripMenuItem item = new ToolStripMenuItem("uniqueName") { Image = WindowsFormsApplication2.Properties.Resources.Search.ToBitmap() };
if (cxtMnuStrp.Items.Contains(item) == false)
cxtMnuStrp.Items.Add(item);
this.ContextMenuStrip = cxtMnuStrp;
}
Note:
If you added a icon to the resource file. You will have to convert it to a image by using .ToBitmap().
The images are now available in intellisense instead of using path strings.
I have added the contextMenuStrip to the form in the example above.
In addition to the information provided on how to add resources in the links above you can add them as follows
Suppose I have one form where a combo box has some options. Now, at the first run of this program, user selects a option from combo box and saved it through a button click or something. Now, If user terminates the application and run again for the 2nd time, is there any way to retrieve the last saved selection?
That means, if you select option1 from the combo box and terminate the application. after some time, you again start the application, now your combo box should show option1 as selected because at the previous session, you selected it.
I hope you'll understand what i think.
Use Settings
// To Load (after combo box binding / population)
private void LoadSelection()
{
int selectedIndex = 0;
if (int.TryParse(Properties.Settings.Default.comboBoxSelection, out selectedIndex))
{
cbMyComboBox.SelectedIndex = selectedIndex;
}
}
// saving on button click.
private void saveButton_Click(object sender, EventArgs e)
{
//set the new value of comboBoxSelection
Properties.Settings.Default.comboBoxSelection = cbMyComboBox.SelectedIndex;
//apply the changes to the settings file
Properties.Settings.Default.Save();
}
See here for more detail.
You have to manually save the value and load it up again when the program starts.
The easy way to do it with Visual Studio is to create a Settings class. In VS, right click your project, click add new, scroll to "Settings File", add. VS will show you a UI where you can create new properties in the settings object that you can chose the name of.
If I create a new property called "ComboboxValue" of type string, I can reference it in the code as Settings1.Default.ComboboxValue = "hello world";
Here's the MSDN on it:
http://msdn.microsoft.com/en-us/library/a65txexh(v=vs.100).aspx
You can add settings
on solution explorer under the project, properties folder
add resource "string" give it a name "selected" for example
then
// this is save button
Properties.Settings.Default.selected = comboBox1.SelectedIndex;
Properties.Settings.Default.Save();
// this is retrieve (use it in window_load event for example)
comboBox1.SelectedIndex = Convert.ToInt32(Properties.Settings.Default.selected);
I'm writing an Expression Blend 4 Extension and I want to detect (in my extension) when a Control or Element on the design surface is selected. Can someone tell me how I can detect it? Thanks, Tim
I've continued a bit on my tutorial on writing extensions. When you look at the sample code of this project the code below should be clear.
The first method below is called when the active document is changed. This method handles the ActiveDocumentChanged event of the IDocumentService. First it gets the content of TimelinePane from the palette registry. In this content lives the ActiveSceneViewModel. The ActiveSceneViewModel is the viewmodel that containse the active scene (= the current xaml file being edited). The ActiveSceneViewModel contains a set of the selected elements, the ElementSelectionSet. Which has an event(Changed) that is fired when it is changed. Handle this event.
In this eventhandler you'll have access to the selection set, directly after it is changed.
private void ActiveDocumentChanged(object sender, DocumentChangedEventArgs e)
{
var timelinePane =
(TimelinePane)WindowService.PaletteRegistry["Designer_TimelinePane"].Content;
_activeSceneViewModel = timelinePane.ActiveSceneViewModel;
_activeSceneViewModel.ElementSelectionSet.Changed +=
new System.EventHandler(ElementSelectionSet_Changed);
//some other goes here....
}
void ElementSelectionSet_Changed(object sender, System.EventArgs e)
{
SceneElementSelectionSet selectionSet
= sender as SceneElementSelectionSet;
// get the selected elements from the selection set
}