
_SBradley_
Avatar/Signature-
Posts
29 -
Joined
-
Last visited
About _SBradley_
- Birthday 04/16/1975
_SBradley_'s Achievements
Newbie (1/14)
0
Reputation
-
Sorry, I thought that would be enough to describe the problem. Here's a "compilable snippet": using System; using System.Drawing; using System.Windows.Forms; class ListViewTest : Form { static void Main() { Application.Run(new ListViewTest()); } ListViewTest() { m_Grid.View = View.Details; m_Grid.Size = ClientSize; Controls.Add(m_Grid); PopulateGrid(); } private void PopulateGrid() { #if PAUSE_UPDATE m_Grid.BeginUpdate(); #endif m_Grid.Columns.Add("Col", 100, HorizontalAlignment.Left); foreach (string str in m_Data) { ListViewItem item = null; foreach (ListViewItem lvi in m_Grid.Items) { if (lvi.Text == str) { item = lvi; break; } } if (item == null) { item = m_Grid.Items.Add(str); } } #if PAUSE_UPDATE m_Grid.EndUpdate(); #endif } private string[] m_Data = {"one", "two", "one", "three"}; private readonly ListView m_Grid = new ListView(); } Compile this with the .NET Framework 1.x with or without PAUSE_UPDATE defined, and you get a list containing just "one, two, three". Compile it for the .NET Framework 2.0 without PAUSE_UPDATE defined, and you still get "one, two, three". But compile it for the .NET Framework 2.0 with PAUSE_UPDATE defined, and you get "one, two, one, three"! (Obviously, in the case of this snippet, a workaround would be to search the array for duplicates; but my actual app does more than this and doesn't use an array, so my only workaround right now is just to not use BeginUpdate/EndUpdate.)
-
I have some code that says something like: ListView lv = ...; lv.BeginUpdate(); foreach (piece of data) { if (an appropriate row already exists) item.SubItems.Add("blah"); else item = lv.Items.Add("blah"); } lv.EndUpdate();[/Code] This used to work as expected in .NET 1.0/1.1. However, since I installed 2.0 Beta 2, the 'if' part never runs; every iteration always inserts a new row, even if I've actually already inserted the specified row. Surely, BeginUpdate/EndUpdate should only affect what's displayed, not what actually gets inserted into the ListView? Is this a bug? Cheers. :)
-
Inheritance with a constructor that takes arguments problem
_SBradley_ replied to aewarnick's topic in Visual C# .NET
It's pretty much the same thing as [CS] class Inherit extends c1 { Inherit() { super("whatever"); } } [/CS] in Java. Only nicer. ;) -
Inheritance with a constructor that takes arguments problem
_SBradley_ replied to aewarnick's topic in Visual C# .NET
The "correct" way to do what you're after is this: [CS] class Inherit : c1 { Inherit() : base("whatever") { } } class c1 : UserControl { public c1() { } public c1(string argument) { // Initialize the class with the argument in this sub } } [/CS] -
Regular Expressions in VB My first ever attempt at VB. Hope it's OK! ;) Imports System.Text.RegularExpressions Imports System.Windows.Forms Public Module IDExtractor Sub Main Dim str As String str = "[3] DOE JOHN" Dim r As Regex r = New Regex("\[(?<id>([0-9]+))\]") Dim m As Match m = r.Match(str) If m.Success MessageBox.Show(m.Groups("id").Value, "ID") End If End Sub End Module
-
Regular Expressions I have to say, I would use a Regular Expression for this purpose. I've written a little example in C#, because I don't know VB; but converting back to VB should be easy enough for you. :) [CS] using System.Text.RegularExpressions; using System.Windows.Forms; class IDExtractor { static void Main() { string str = "[3] DOE JOHN"; Regex r = new Regex(@"\[(?<id>([0-9]+))\]"); Match m = r.Match(str); if (m.Success) MessageBox.Show(m.Groups["id"].Value, "ID"); } } [/CS]
-
[*]You misspelt "Length". [*]'i' is out of scope by the time you come to the second loop. I presume this was meant to be a nested loop. Since only the first statement is inside the first loop, you would need to enclose the two statements in a pair of braces. [*]C# is case sensitive: MessageBoxButtons has a member 'OK', but no member 'ok'. [/list=1] Also, your inner loop was counting from 1 to n - 1, so would have printed one too few asterisks. Here's an alternative, using a string constructor instead of a nested loop: [CS] using System; using System.Windows.Forms; class Histogram { static void Main() { int[] n = { 3, 4, 6, 8, 10, 9, 15 }; string output = "element\tsubscript\thistogram\r\n"; for (int i = 0; i < n.Length; i++) output += i + "\t" + n + "\t" + new string('*', n) + "\r\n"; MessageBox.Show(output, "histogram", MessageBoxButtons.OK, MessageBoxIcon.Information); } } [/CS] Hope you like that. :cool:
-
If I run the following code on a 16-colour bitmap, the changes to the palette are not included in the saved image. However, the image displayed in the form is as I expected (black & white). Am I doing something wrong, or is this a bug? [CS] using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; class Test { static void Main(string[] args) { Bitmap bmp = new Bitmap(args[0]); ColorPalette pal = bmp.Palette; for (int i = 0; i < pal.Entries.Length; ++i) pal.Entries = i == 0 ? Color.Black : Color.White; bmp.Palette = pal; bmp.Save("new.bmp"); new ImgForm(bmp).ShowDialog(); } } class ImgForm : Form { public ImgForm(Bitmap bmp) { m_Bitmap = bmp; } protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; g.DrawImage(m_Bitmap, ClientRectangle); } private Bitmap m_Bitmap; } [/CS]
-
TrayIcon is now called NotifyIcon. There is actually a subtleish difference between the ShowInTaskbar and Visible methods. If you set Visible to false, then, when you Alt+Tab between applications, your application will not be in the list. With the ShowInTaskbar method, your application will still be there (although it turns out to be a "blank window" icon -- this seems like a bug...?). I didn't have a problem with either method, though: you just have to make sure to reset the rest of the state (make it visible or whatever) before resizing the form.
-
Your method is called ror(), which I presume stands for "rotate right", but your code shifts left -- although the highbit part looks good for a right-shift method. It's a little confused... ;) I had a quick go, and came up with this pair: [CS] class Rotate { public static byte RotateLeft(byte val) { byte lowbit = (byte) ((val & 0x80) != 0 ? 0x1 : 0x0); val <<= 1; val |= lowbit; return val; } public static byte RotateRight(byte val) { byte highbit = (byte) ((val & 0x1) != 0 ? 0x80 : 0x0); val >>= 1; val |= highbit; return val; } } [/CS]
-
What sort of errors? GetType() should never cause any errors. And it cannot be overriden, because it is not virtual in Object.
-
'watcher' is an instance member of your StartUp class. However, you are trying to reference it from Main(), which is a static method. Since a static method does not have an implicit 'this' reference, you cannot reference instance members, only static members. You have three choices: 1. Declare and initialize 'watcher' inside your Main() method, instead of making it a member. 2. Make 'watcher' a static member of your StartUp class (just declare it "static FileWatch watcher"). 3. Create an instance of class StartUp and use that, as in "new StartUp().watcher.StartWàtch()".
-
Instead of using typeof(Second), just call obj.GetType(). :)
-
There's only one instance of the DLL. You'll have to solve this problem in code, either or the client side or on the server side. (I can't really say which would be best without further details.)
-
It's very easy with .NET. [*]Build your DLL using the /t:library command-line switch. [*]In your application code, add any using directives for namespaces defined in that DLL, if you fancy, and use the classes and methods in which you're interested. [*]Build your EXE using the /r:MyDll.dll command-line switch. [/list=1] Voilà! (I don't know what magic you must perform in order to do this via your IDEs.)