|
This works....
namespace Test
{
public class MyPicturebox : System.Windows.Forms.PictureBox
{
public delegate void ImageChanged ( Object sender, EventArgs e );
public event ImageChanged OnImageChange;
public new Image Image
{
get { return base.Image; }
set
{
base.Image = value;
if (OnImageChange != null)
{
OnImageChange(this, new EventArgs());
}
}
}
}
public partial class Form1 : Form
{
public Form1 ( )
{
InitializeComponent();
PictureBox _PB = new PictureBox();
}
}
}
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
' This picturebox has BeforeImageChanged and AfterImageChanged events.
' Taken from http://thedotnet.com/nntp/96040/showpost.aspx
'
Imports System
Imports System.Windows.Forms
Imports System.Drawing
'
Public Class MyPictureBox
Inherits PictureBox
Private _image As System.Drawing.Image = Nothing
Public Event BeforeImageChanged(ByVal sender As Object, ByVal e As EventArgsImageChanged)
Public Event AfterImageChanged(ByVal sender As Object, ByVal e As EventArgsImageChanged)
Public Shadows Property Image() As Image
Get
Return _image
End Get
Set(ByVal Value As Image)
If Not Value Is _image Then
If Me.DesignMode Then
MyBase.Image = Value
_image = Value
Else
Dim ea As New EventArgsImageChanged
If _image IsNot Nothing Then
RaiseEvent BeforeImageChanged(Me, ea)
If ea.Cancel Then
Exit Property
End If
End If
MyBase.Image = Value
_image = Value
RaiseEvent AfterImageChanged(Me, ea)
End If
End If
End Set
End Property
End Class
Public Class EventArgsImageChanged
Inherits EventArgs
Private _cancel As Boolean = False
Public Property Cancel() As Boolean
Get
Return _cancel
End Get
Set(ByVal Value As Boolean)
_cancel = Value
End Set
End Property
End Class
|
|
|
|
|
I have a simple file naming app, and what I would like it to do is: When the user 'pastes' the clipboard text, update the clipboard with the next item.
So I knew I had to recieve messages which I've got to work. But the problem is my app only gets WM_DRAWINGCLIPBOARD, which doesn't seem right (its to 'early' in the cycle).
I think the problem is that I need to respond to messages sent to the other app (explorer), but I'm not sure how to do that in c#.
Failing that, what's the best way for an app to respond to a global key press? i.e. whatever app has focus, when the user press X do this.
|
|
|
|
|
cjb110 wrote: Failing that, what's the best way for an app to respond to a global key press? i.e. whatever app has focus, when the user press X do this.
You should create keyboard hook to handle that.
To capture copy,paste, ... you could use WM_COPY,WM_PASTE and etc.
Life is a stage and we are all actors!
|
|
|
|
|
I started with WM_Paste, but my app never receives that message, only WM_DrawingClipboard. I think because its not the target of the paste.
I'm think the global key press is probably more 'safe' in the long term.
|
|
|
|
|
cjb110 wrote: I started with WM_Paste, but my app never receives that message, only WM_DrawingClipboard. I think because its not the target of the paste.
Have you read WM_PASTE documentation first?
You cannot receive it into Form.WndProc because it's sended to some editable controls only.For example:
public class MyTextBox :TextBox
{
const int WM_PASTE = 0x302;
protected override void WndProc(ref Message m)
{
if (m.Msg ==WM_PASTE)
{
MessageBox.Show("WM_PASTE was fired");
}
base.WndProc(ref m);
}
}
Life is a stage and we are all actors!
|
|
|
|
|
Sorry, that's what I meant. I understood that the WM_PASTE gets sent to the target, and I know my app isn't the target!
What I hoped was possible, was that I could respond to the general message being sent to any target.
I'm going to look further into WM_DrawClipboard, as you seem to get two of those every time paste occurs, couldn't see any thing in msg, but I'm hoping one is sent before the 'pasting' occurs, and the other when its finished.
|
|
|
|
|
But the problem is my app only gets WM_DRAWINGCLIPBOARD, which doesn't seem right (its to 'early' in the cycle).
what is the wrong with this...
clipboard activity data can be handled only through WM_DRAWINGCLIPBOARD only.
|
|
|
|
|
I am writing a multithreaded application. A download manager to be precise. When downloading one file, everything is quite fine. The thread starts, downloads the file and terminates as expected. When i start another download thread, however, when the first is still running, i get the error above 9in the subject). The problem is on this line of code which is meant to create a new filestream and write the retrieved data to the stream.
strLocal = new FileStream(Application.StartupPath+"\\"+SaveAsTextBox.Text,FileMode.Create, FileAccess.Write,FileShare.ReadWrite);
The download method is called Download(), is void and does not take any arguments.
A thread is started using
DownloadThread[j] = new Thread(new ThreadStart(Download));<br />
DownloadThread[j].Start();
where j has a value incremented per click, so as to start a new thread each time.
What i do not understand is that the exception seems to suggest that 2 write operations are requesting to be handled by the same stream, yet it is actually a different stream because the user changes the SaveAsTextBox.Text on every new download.
Any answers?
BHM
|
|
|
|
|
Sounds like you're trying to write to the same file on two threads ? That plainly won't work.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
What is the actual value of "SaveAsTextBox.Text" in each of the threads?
|
|
|
|
|
for each of the threads, it is different. say AAA.avi for one and BBB.avi for another. The two are meant to be written to the same forlder nonetheless.
BHM
|
|
|
|
|
Maximus Byamukama wrote: say AAA.avi for one and BBB.avi for another. The two are meant to be written to the same forlder nonetheless.
Yes, but what are the actual values? Have you checked the filenames in both threads at execution time?
|
|
|
|
|
Hello,
i want to make an application, which runs in the background. But maybe not a service, because i maybe let it run under mono and under linux. And i had a few problems, to start the service...
But now the problem, how can i let my application run in the background? I don't want, that it close itself if it's finished with the "Main-Method", because i have a few events and connections which listen on some ports.
I think it should work with
while(true)
{
}
but doesn't such a loop need a lot of resources??
Thanks
|
|
|
|
|
Hi,
I would do the following. Within the Main-Method start a thread to do the main-work (whatever your application should do). After you started the thread, use a Console.ReadLine() to wait for user-input to stop the application.
It should look like this:
public static void Main(string[] args) {
while(true) {
string input = Console.In.ReadLine();
if("stop".Equals(input)) {
break;
}
}
}
Regards
Sebastian
|
|
|
|
|
Does this make sense, what else can a console app do at this point except sit there looking black.
|
|
|
|
|
Well as already mentioned the console app could run like a service. For example like starting Apache Tomcat in console etc.
|
|
|
|
|
|
You could use a ManualResetEvent:
public static ManualResetEvent stopEvt = new ManualResetEvent(false);
static void Main(string[] args)
{
stopEvt.WaitOne();
}
Then, in your listening thread you can use stopEvt.Set(); to close the application.
|
|
|
|
|
I need a pointer to an article that can help me with gridviews that are sortable, users can add and delete rows, and some of the columns are dropdowns referencing various datasets. The question is too complicated to Google or Search And not even one of my 23 books handles that situation.
the values of e.RowIndex and e.Row.Index are no longer useful unless the table you use for the dropdown also gets sorted when you sort the gridview, or you use some sort of double-value table so you have a cross-reference to the correct row in the grid's dataset.
I have considered using a struct or a dictionary for the dropdown's table, and then catching the Sort event to sort the struct/dictionary. Or updating the sort of the struct/dictionary on Paint, but maybe there is a better way. One of my grids consists only of 8 dropdowns, each pointing to a different dataset.
Thanks.
modified on Wednesday, September 2, 2009 2:08 AM
|
|
|
|
|
Are you using a GridView or a DataGridView (win or web).
This article helped me with a DGV [^]
|
|
|
|
|
I am using a DataGridViews on Windows forms.
Had a look at the article, but it does not handle my problem: sortable, with comboboxes, and adding/deleting rows.
Essentially, the question: which is the best way to handle the list of values that must be displayed in the combobox column - use a dictionary or a struct and sort the dictionary/struct when the grid is sorted, or maybe some other method.
I started off using an ArrayList of int, but then I have no reference to sort it to the same order as the grid. So it has to be an ArrayList of a struct that stores the value that must go in the combobox and a value from some other column in the grid so that I can sort the ArrayList to the same order. And it starting to boggle my mind!
|
|
|
|
|
Nigel Mackay wrote: And it starting to boggle my mind!
I have only once EVER used a combo in a DGV, I'm of the school that says you do not edit data in a list control, I allow this to vary only on the most trivial operations so sorting a DGV with a combo in it is (and will stay) outside my scope.
If your underlying data is a datatable/view then sorting should not be an issue if you bind to the text rather than the ID. Then how do you deal with the 'I sote the ID' problem.
|
|
|
|
|
Not making the data in the gridview editable could very well be the the answer to my problem.
Use the grid, sortable, for viewing and for finding the row to edit, and then using Add, Delete and Edit buttons to open dedicated forms for the three tasks. The row number doesn't have to used per se, a suitable value can be extracted from the grid in order to decide which record to Edit. And I still have the row number to put the edited values back into the grid. Deleting just needs confirmation. Adding can gather the data and then insert a row into the grid programatically.
Will go that route - it just means creating a few more forms - 6 to be exact.
Maybe the problems associated with what I was trying to do explains why I can find no info about it.
|
|
|
|
|
Nigel Mackay wrote: 6 to be exact
Meh - I've got hundreds of the bloody things for editing....
I put the id value I want into column[0] and set visible to false - I then know exactly where to find my edit id. I have also been known to chuck the datarow into the tag property if I am manually loading the DGV (I consider this cheating but it does make locating the record simple)
I use doubleclick on the cell/row to initiate the edit operation and also have a toolstrip with AED buttons.
|
|
|
|