|
you're welcome.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
fixed a bug
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
can anyone point me in the right direction on how to right click on a listbox entry and be able to rename it.
my project logs video clips in 60 sec files and stores them in a folder, i use filesystemwatcher to populate a listbox of with the file names as they are created
minute 1
minute 2
minute 3
and so on...
i want to be able to select a file and rename it so i can find that bit of video quicker
so far i got
private void listBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
//not sure what to add here
any help would be great
using visual studio 2008 c#
kenny
|
|
|
|
|
Hi,
1.
why use MouseDown? I would set SelectionMode.One, then use SelectedIndexChanged event and SelectedIndex property. Don't forget to check for >=0. Or better yet, use DoubleClick event, so user must double click to enter rename mode.
2.
how will you enter the new name? just typing at the ListBox? trough a TextBox?
and when do you want to rename? on hitting Enter? clicking a Button?
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
would like to enter new name by just typing at listbox, dont want to double click as i use that for playing the video file
kenny
|
|
|
|
|
I would go with Scott's suggestion (context menu), hence use the SelectedIndexChanged event, and the KeyPress event.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
I would use a context menu.
When the user right-clicks and selects rename you can pop up a dialog asking for the new value to be input into a textbox.
When the user clicks OK you can just update the selected item text to the text they entered.
|
|
|
|
|
Does anyone know any way to set a process to be the foreground window in managed code, I have a Process object and need to set that process to be the front form. I was previously using the user32.dll function SetForegroundWindow(p.MainWindowHandle); , but I know have a requirement to use only managed code. Any ideas?
|
|
|
|
|
If the window is one in your application then you can call Activate(); on the instance and it will activate the form.
Why only managed code? Alot of the managed classes are just wrappers around the native stuff (or wrappers around managed wrappers!), calling API functions yourself is just the same so long as it is done correctly.
|
|
|
|
|
The process is not in my app, so the Activate(); trick wont work for me. The managed code is a microsoft certification requirement. It's fine if there are 3rd party assemblies in my project that call unmanaged code, but there cannot be any in any of the code I've written.
|
|
|
|
|
|
This has been stated quite a few times, format your code (using the pre tags) or it will just get ignored.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I'm trying to make a class that will simply put the progress bar in a loop (just to see how it works for learning purposes). I keep getting the following error though and I don't understand why.
error
Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on.
here is the class code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class thread
{
private thread trd;
private ProgressBar _threadProgressBar;
public ProgressBar ThreadProgressBar
{
set { _threadProgressBar = value; }
get { return _threadProgressBar; }
}
public void startthread()
{
Thread trd = new Thread(new ThreadStart(this.ThreadTask));
trd.IsBackground = true;
trd.Start();
}
private void ThreadTask()
{
int stp;
int newval;
Random rnd = new Random();
while (true)
{
stp = ThreadProgressBar.Step * rnd.Next(-1, 2);
newval = ThreadProgressBar.Value + stp;
if (newval > ThreadProgressBar.Maximum)
newval = ThreadProgressBar.Maximum;
else if (newval < ThreadProgressBar.Minimum)
newval = ThreadProgressBar.Minimum;
ThreadProgressBar.Value = newval;
Thread.Sleep(100);
}
}
}
}
i'm calling it inside a windows form
with
public void callthread()
{
thread mythread = new thread();
mythread.ThreadProgressBar = progressBar1;
mythread.startthread();
}
thanks
|
|
|
|
|
Seems I wrote this[^] especially for you.
BTW: entering the error message in the Google search box usually leads to the solution right away.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Just for him? Do you take requests
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: Do you take requests
Not normally. I do take hints though.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
haha thanks for taking the time and writing that article just for me. I feel special
Anyway, thanks again.
|
|
|
|
|
I have form with lot's of TextBoxes and also there is a lot of threads in my program that need to read content's of those TextBoxes (settings). Since I can't access controls from other threads, I decided to make special class that will hold all the settings, and if user changes some, control will invoke OnTextChanged event and change corresponding value in class. But if I use that approach there will be a lot of similar handlers tike this
private void txtCrap1_TextChanged(object sender, EventArgs e)
{
Settings.Crap1 = txtCrap1.Text;
}
What I want is to do something like this
private void SetUpControlBindings()
{
AddBinding(txtCrap1, Settings.Crap1);
AddBinding(txtCrap2, Settings.Crap2);
}
private void AddBinding(object control, object value)
{
}
private void UpdateValue(object sender, EventArgs e)
{
if (sender is TextBox)
{
}
}
But I can't find any pointers to variables in C# Any ideas how to do this?
Actually my program is a bit more complicated. I have not only textboxes, but CheckBoxes, NumericUpDowns etc. also I want my Settings class to hold some additional objects like Lists.
P.S. I can't use reflection since my code will be obfuscated after compilation
|
|
|
|
|
Hi,
it is pretty easy to create a method that returns the Text (or any other property) of a Control, even from an unrelated thread. Look for "Retrieving information from a Control" in this article[^].
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
I can't do it because threads will read settings in a loop, much more often than settings will change. So if I'll use Invoke it will cause big performance problems.
|
|
|
|
|
then make a local copy before entering the loop, and possibly update every so often.
most of the time, my apps have several controls and a "start" button, control values only get read when "start" is clicked, i.e. the job definition is static. When it has to be dynamic, I always consider using a Forms.Timer to update a set of variables periodically, i.e. I don't invest in data bindings if I can avoid them easily.
However, if you want it truly event-driven and are willing to databind everything, that is just fine.
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. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
Yeah, that's a good idea. I think i'll do like you saying
|
|
|
|
|
Why do you need to create several OnTextChange even handlers? One is all you need.
private void TextChanged(object sender, EventArgs e)
{
TextBoxctrl = sender as TextBox;
Settings[ctrl.Tag] = ctrl.Text;
}
private Dictionary<string, string> Settings{get; set;}
Add the tag to each textbox that will correspond the to dictionary key.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
To use dictionary for settings is a good idea, but I need to stote not only TextBox.Text but also Checkbox.Checked, NumericUpDown.Value, TextBox.Lines etc. So if I'll use dictionary it will result in lot's of type casts. Maybe you can modify your method to take this into account?
|
|
|
|
|
PomaPomaPoma wrote: Maybe you can modify your method to take this into account?
No, it's your project. If you want me to do your work email and we'll discuss rates.
I know the language. I've read a book. - _Madmatt
|
|
|
|