|
Have you considered creating a form that would always be on top in your main method? Creating it from the start, then all the other windows would be under your control as well but would be fired up after the creation of your logging form.
This is assuming that I've understood your problem correctly.
|
|
|
|
|
Here's one way, create a test project with:-
2 Forms (Form1 and DebugWindow)
1 "Logger" class.
Form1 just has 2 buttons on it, 1 to write an entry to the "Logger" class,
the other to "Show" the Debug form.
The DebugWindow form just has a Listbox on it.
The Logger class has a static method which can be called from any class in your project,
which in turn writes an entry in your DebugWindow listbox.
Here's the Form1 class.
<<<
public partial class Form1 : Form
{
DebugWindow dbug;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dbug = new DebugWindow();
dbug.Show();
Logger.DebugWindow = dbug.DebugListBox;
}
private void button1_Click(object sender, EventArgs e)
{
Logger.LogIt(DateTime.Now.ToString("dd MM yyyy HH:mm:ss.fff"));
}
private void button2_Click(object sender, EventArgs e)
{
dbug.Show();
}
}
>>>
Here's the DebugWindow class.
<<<
public partial class DebugWindow : Form
{
private ListBox _debugListbox;
public DebugWindow()
{
InitializeComponent();
}
//
// hide form
//
private void hideToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
}
//
// Properties
//
public ListBox DebugListBox
{
get { return _debugListbox; }
set { _debugListbox = value; }
}
private void DebugWindow_Load(object sender, EventArgs e)
{
DebugListBox = listBox1;
}
}
>>>
Here's the Logger class.
<<<
class Logger
{
private static ListBox _debugWindow;
//
// Log Message
//
public static void LogIt(string sData)
{
sData = sData.Trim();
UpdateListBox(sData);
}
//
// output to listbox
//
delegate void ListBoxStringAdder(string sInfp);
private static void UpdateListBox(string sInfo)
{
int iLines = 999;
if (DebugWindow.InvokeRequired)
{
ListBoxStringAdder lsa = new ListBoxStringAdder(UpdateListBox);
DebugWindow.Invoke(lsa, new object[] { sInfo });
}
else
{
if (DebugWindow.Items.Count == iLines)
{
DebugWindow.Items.RemoveAt(iLines - 1);
DebugWindow.Items.Insert(0, DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " | " + sInfo);
DebugWindow.SelectedIndex = 0;
}
else
{
DebugWindow.Items.Insert(0, DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + " | " + sInfo);
DebugWindow.SelectedIndex = 0;
}
}
}
//
// Properties
//
public static ListBox DebugWindow
{
get { return _debugWindow; }
set { _debugWindow = value; }
}
}
>>>
|
|
|
|
|
Hi, I am a VB.NET programmer trying to get to grips with C# and it seems as far as I can see that events in VB are very different in C#
I have this in VB:
Public Class CGeneralParameters
Implements IDisposable
Public Event ClassError(ByVal e As ClassErrorData, ByVal CriticalError As Boolean, ByVal MustDisplay As Boolean)
Private m_strConnectionString As String = ""
Private m_sAppData As String = ""
Private e As ClassErrorData
The code translator has done this to it:
<pre>public class CGeneralParameters : IDisposable
{
<big>private ClassErrorData e;</big>
private bool CriticalError;
private bool MustDisplay;
private string m_strConnectionString = "";
private string m_sAppData = "";
<big>private ClassErrorData e;</big>
public CGeneralParameters()
{
and has pushed the structure to the end of the class.
Can I use events in this DLL to pass errors back to the calling program, or shouyld I be looking at another way to do this?
|
|
|
|
|
Generally, code translators are not the best at converting code from one language to another. There will be something missing.
From what you've posted, I can't really see where the problem is. Event declaration in a class is not important, assigning it (aka wiring) is. And yes, any exceptions thrown by a dll method that has been called by your application will be captured in the calling method as long as it is not being handled in that method.
|
|
|
|
|
Use a different converter - this code is very simple to convert.
In VB, you can specify an event combined with an implicit delegate.
The conversion to C# (via Instant C#) is:
public delegate void ClassErrorEventHandler(ClassErrorData e, bool CriticalError, bool MustDisplay);
public event ClassErrorEventHandler ClassError;
(the formerly implicit delegate has been named 'ClassErrorEventHandler' in the conversion).
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
VB & C# to Java Converter
Java to VB & C# Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB, C#, or Java to C++/CLI
|
|
|
|
|
Is there a way to (check/scan through network) ip addresses of listening ports in a network
|
|
|
|
|
Probably you have to connect to it, if you get an exception -> port closed, otherwise successfull, then close it.
|
|
|
|
|
If you put the server listining you will(or not) accept clients and by that get their ip.
Having the ip´s send whatever package you want to.
I assume that you didn´t start yet. Download some application here and see the code, if you have doubts ask here then.
|
|
|
|
|
I am new to .NET interoperability. I need to write some C++ code which would access the methods of a .NET component. Any help is greatly appreciated.
Regards,
|
|
|
|
|
|
I am developing a project in which , application will search all the computers in a network, ranging from 100-10000 and then write all the software's installed in every machine in a single text file.
please suggest me
1)Is it feasible to create a thread for every machine an d in that thread i would search the machine details.
2)Do a serial search 1 by 1.
3. or create a limited number of threads say 25 for first 25 machines then, wait if any thread is available , if a thread is available then allot it new machine.
which option is best and more fast...........
|
|
|
|
|
I'd go with 3rd one. It's more efficient as you are re-using threads.
|
|
|
|
|
That depends a little on what you mean by "best", and somewhat on the hardware.
Option one is not practical with the number of threads that you specified.
Option two would work well as a long running background process, as it doesn't hog the computer or the network.
Option three is fastest. The optimal number of threads is difficult to predict, though. Make it configurable, so that you can try some different settings.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hi all,
i filter a datagrid with respect to a texbox input. It filters fine. But how do i bring back the original data into the grid when the textbox is empty?
code below:
<br />
if (txtQS.Text.Trim != "") {<br />
TMSDataSet.LASTIDNOREFFDataTable dt = new TMSDataSet.LASTIDNOREFFDataTable();<br />
LASTIDNOREFFTableAdapter.Fill(dt);<br />
DataView dv = new DataView(dt);<br />
dv.RowFilter = "lastmonth = " + txtQS.Text;<br />
LASTIDNOREFFDataGridView.DataSource = dv;<br />
LASTIDNOREFFDataGridView.Refresh();<br />
}<br />
else <br />
LASTIDNOREFFTableAdapter.Fill(TMSDataSet.LASTIDNOREFF);<br />
Thanx.
He who goes for revenge must first dig two graves.
|
|
|
|
|
Have you tried clearing the filter? You might want to check if the textbox where the filter criteria being written is empty, you might want to clear the RowFilter property.
|
|
|
|
|
Hi,
My advice is simply, do it with SQL store procedures.
Don´t filter, sort, edit in c#. Do the store procedures and trigger then in c#, with whatever event you want button_click, form_load etc.
It´s very easy
If you have doubts ask here how to make them(SP).
Good Luck
|
|
|
|
|
I want to develop an object tracking application using a web cam. I have captured the video using visual C# 2005. And now I stuck in finding way to obtain pixel color values of incoming video frame.Please can anyone tell me how to obtain RGB values of incoming video frame into an array.
Dhanushka
|
|
|
|
|
Hi,
welcome to Code Project.
This site not only has discussion forums, it also hosts aa wealth of articles.
I recommend the search facilities.
You might find very interesting articles such as this one[^] and its sequel.[^]
They also contain valuable references.
Hope this helps.
|
|
|
|
|
'This get from image saved in ur pc.I am 'using picture box mouse click event in visual basic.Net '2010 .Add pic box to ur form & add these lables to y 're form thanks
'Enjoy this
' Yohan & Laleen From Sri Lanka
Dim TempBitmap As New Bitmap(PictureBox1.Image)
Dim MyColor As Color
MyColor = TempBitmap.GetPixel(e.X, e.Y)
' MessageBox.Show("Pixel x=" & e.X & ", y=" & e.Y & ", color=" & MyColor.ToString, "Color", MessageBoxButtons.OK, MessageBoxIcon.Information)
Label5.Text = MyColor.R.ToString()
Label6.Text = MyColor.G.ToString()
Label7.Text = MyColor.B.ToString()
Label8.Text = e.X.ToString()
Label10.Text = e.Y.ToString()
Dim r1 As String = Hex(MyColor.R)
Dim g1 As String = Hex(MyColor.G)
Dim b1 As String = Hex(MyColor.B)
'MessageBox.Show(r1 & g1 & b1)
Label12.Text = r1 & g1 & b1
|
|
|
|
|
Not sure what this is called exactly. I am after creating a method or class you can pass variables to. I want to be able to give them a pre-set list of what variables they can pass e.g. "txtOutcomes.TextMode = " automatically brings up "TextBoxMode", where you can select ".MultiLine;". Hope this makes sense. Many thanks.
Ric
|
|
|
|
|
Its not very clear what you are trying to achieve, but I'm fairly certain you are going to be way out of your depth.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
its called an enum, you define one as follows:
public enum MyEnumeratedValues
{
MyValue1,
MyValue2,
MyValue3
}
You can then have a property of this type on your class
public class MyClass
{
private MyEnumeratedValues aProperty;
public MyEnumeratedValues AProperty
{
get{ return aProperty; }
set{ aProperty = value; }
}
}
now when somebody creates an instance of your class and sets the AProperty property, intellisense will show them the 3 values defined.
I think thats what you're after
|
|
|
|
|
Fantastic! That's loads of help. Many thanks.
|
|
|
|
|
I have populated a treeview (tvwResults) with some data such as:
item1
subitemA1
subitemB1
item2
subitemA2
subitemB2
subitemB3
subitemB4
item3
subitemA3
...
...
...
I have added an imagelist control with three images with indexes 0, 1, 2
for error, fail, warning
I am tying to assign the correct image to each item and subitem accordingly...
For example, if there is an error in one of the subitems, then that subitem will have the image of error which is index 0 and so the image for that item i.e. the item will be warning i.e. index 2
And if all the subitems of an item have fail in the text then the image for the item will be error too.
I have started working on the following code.
Question:
can you please see if what i am trying to do in this code is correct based on the above request?
Thanks
foreach (TreeNode n in tvwResults.Nodes[0].Nodes)
{
foreach (TreeNodeCollection nc in tvwResults.Nodes[0].Nodes)
{
if (nc.ToString().ToLower().Contains("error"))
{
nc.ImageIndex = 0 // error...
????
}
}
}
|
|
|
|
|
Put your image in ImageList.
Then use : nc.StateImageIndex = 0; // or 1, or 2, ...
|
|
|
|