Hi VinceAshbySmith, I made your sample project, how can I provide the zip file ?
Jean-Christophe Grégoire
Hi VinceAshbySmith, I made your sample project, how can I provide the zip file ?
Jean-Christophe Grégoire
I certainly do agree, I didn't want to bother him ;-)
Jean-Christophe Grégoire
Okay sorry, give me some more time and I will mail you a sample project ;-)
Jean-Christophe Grégoire
Don't do that like that, compute the letters list where you want, give it to your "grid container" UserControl which it is supposed to know the list of "letter controls" that it contains. Loop in your letters list and give a letter to each sub-control. Each sub-control is supposed to have a stupid Text property, in which you can set the value of a label that would be docked full in your sub-control. Really, don't put all this useless complexity like that.
Jean-Christophe Grégoire
You are instantianting a new Form1, this is not the existing Form1 that opened your second form. When the first form opens the second, it should provide a reference to itself that you can then use in the second form. Optionally, you can check the Owner/ParentForm properties or something like that, depending on how you show the second form. public partial class Form2 : Form { private Form1 _parentForm; public Form2() { InitializeComponent(); } public Form2(Form1 parentForm) { InitializeComponent(); this._parentForm = parentForm; } private void button1_Click(object sender, EventArgs e) { if (this._parentForm != null) { this._parentForm.Add(); } } In this example, your Form1 code is supposed to do something like: Form2 form = new Form2(this); form.Show();
Jean-Christophe Grégoire
You should try a more object-oriented approach, you are really complexifying your life. Split this code in multiple small elements responsible of a single responsibility. The rectangle that holds a letter is one object. If you make a UserControl for this simple responsibility, you can delegate the complexity of catching MouseEnter/MouseLeave/etc... events in the control itself. Via two small event handlers, you can highlight and unhighlight your control without having to determine any coordinate. The "host" of you multiple rectangles is another UserControl. Its only responsibility is to put all the small rectangles in a bigger rectangle. Eventually, it computes the size that a single "letter rectangle" can have, as it knows it own size and the total number of smaller rectangles to put in itself. And finally, generating letters is another responsibility. The generation of the letters occurs outside, is provided to the big UserControl, and it will instantiate the correct number of small rectanges, providing the text and the size. Don't play with positioning that you compute yourself, use docking. All this code can be reduced to 10 lines.
Jean-Christophe Grégoire
A numeric is not a string, but you can convert the NumericId to a string in a query. Only then can it be compared with a string.
Jean-Christophe Grégoire
In .Net, reference types are also objects. That means that most of the commands that you are looking for are present in the string itself. You can play with stuff like: String test = "abcd"; int index = test.IndexOf('b'); String test2 = test.Substring(index); // etc... There are plenty of methods on the string object. There are also static methods in the String class, like for example: String.Compare(string1, string2...) Last but not least, the namespace you are looking for is simply System.
Jean-Christophe Grégoire
Sadly enough, this control does not expose a border color, even for classes inheriting from it. Your only choice is to draw it yourself, you can for example create a class that inherits from the PictureBox and override the OnClick (or just handle it) to paint the border, it can be something like that: public class PictureBoxEx : PictureBox { protected override void OnClick(EventArgs e) { base.OnClick(e); Pen pen = new Pen(Color.Red); this.CreateGraphics().DrawRectangle(pen, base.ClientRectangle); } } This code is not entirely correct, the base.ClientRectangle rectangle is inside the real border but I'll leave it to you to compute the correct coordinates. The disadvantage of this approach is that it is not done in the "Paint event" of the control, so any redraw (caused if you ALT-TAB or just move something over it, like another window) will cause the control to redraw itself and your border will disappear. I don't know what you really want, if the idea is that it should STAY colored after the click, then override the OnClick and trigger the OnPaint after having set a boolean or so to indicate the clicked state; in the OnPaint, check this boolean and draw the border if the "clicked" state check is positive. Another disadvantage, but this was really quick code to show the idea, is that I am using a Graphics object that I create myself. In the OnPaint handler, you should use the provided Graphics object from the eventArgs, otherwise you loose Double-Buffering.
Jean-Christophe Grégoire
Exceptions generally match with their namespace and are thrown via their public members (although, a property should never throw an exception). You are not really supposed to make plenty of exceptions for the tons of different possible problems. Exception handling is really about exception handling. A public method in System.IO.File.Read() could for example throw a System.IOException , without more. Internally, you don't have to handle that at many levels, you just leave it going up till the public method that was called. In this public method, you may indeed have a problem because another component lower in the chain had a problem, for example a network problem during the Read operation. Well, yes, then you receive a System.NetworkException for example, you catch it and rethrow a new exception of type System.IOException with the original exception provided as "inner exception". This is the normal way of doing. So, imagine that you create a new library ComicSoft.ZipUtilities , in the simplest case possible, you can think of one single custom exception for the whole assembly called ComicSoft.ZipUtilities.ZipUtilityException which could be thrown by any public method. And when you have to throw your custom exception because something else crashed, you just give the original exception as parameter when you instantiate it. This is really the simple and academic case, exception handling and rethrow policies is a huge debat ;-) Exception handling can be made much more elaborate, and exceptions should ideally be forseen to be technically useful. Forsee codes, categorize exceptions, find ways to help locating the problems etc... But in its simplest form, what you should do is one or more exception for public methods, depending on the different possible feedbacks that you think will need to provide. If you start doing that internally, then it really should be to use the exception type as condition to execute real handling.
Jean-Christophe Grégoire
I may be mistaking, but I think there is only the MONO implementation that makes it possible to run the .Net framework on a Linux/Unix machine (and therefore also Mac I presume), and it supports only the versions 1, 1.1 and 2.0 of the framework currently. This is really a gigantic work and it is not done by Microsoft, I don't think it is possible.
Jean-Christophe Grégoire
Exception handling is by definition about HANDLING an exception. When you want to display a friendly message, you are not handling anything. Handling an exception is for example retrying a connection to a remote machine after a timeout exception. This is real exception handling. Another form of exception handling is finding an alternative in case of disk I/O problem... writing on another disk or requesting the user to free some space for example. Any other thing that you might want to do, like logging or displaying a message, should be placed at one single location within your application, potentially the application controller. This "application host" component (it can be your Program.cs as well...) is supposed to do something (log, display a popup, exit the application or close the form, or whatever you think may be appropriate). But it can terminate as well, it is up to you to decide when your application is stable, and when it is not. Exception handling means what it says, you handle an exception when you can do something with it, otherwise you leave it going up the stack till it reaches the entry point. JC
Jean-Christophe Grégoire
You create a .Net DataSet in memory, and immediately you do: myDataSet.Tables["events"].NewRow();//on this line Don't you think that your forgot to create a DataTable called "events" ? ;-) You are not accessing any Database here, you are instantiating a DataSet object and you attempt to access a DataTable that you don't have created. I suggest reading some article about ADO.Net, it explains very well how to connect to a Database, retrieve data from it encaspulated in a DataSet, update data and stuff like that.
Jean-Christophe Grégoire
The .Net compiler produces "intermediate language code" from the higher-level language, which is for example C# or VB.Net. This intermediate language code is common to all languages, and this is the code that actually gets executed by the framework. Therefore, if you compile a C# project, it just becomes a .Net assembly; it is almost an executable, it is not your text source file anymore. From the moment that you reference it in your VB.Net project, it becomes available to your VB.Net code as if it was written in VB.Net.
Jean-Christophe Grégoire
Hello, This is normal, what you see as one logical operation actually involves two different physical operations that throw this event. I've learnt that a few years ago, I just can't remember what were the physical operations exactly but it made sense. Something already occurs when the file gets opened or when the write operation is not yet flushed, but the fact is that you can actually detect that. A the first event, the file size is not yet correct: in the case of a new file, the size will be zero, and for modifications... well you have to know the previous size ;-) Below is a sample of something I wrote a few years ago, please forgive me I wrote it in VB and I am not particularly proud of this piece of code ;-) Here, I had the advantage that I was monitoring one file, so I kept remembering its size. I remember there is a more elegant solution in the source code of Log4Net, the popular open source logging framework. They use a file system watcher to watch their own config file for changes. If I remember well, they make use of timer or something like that, the technique works always and you always get only 1 event. Sorry it is late for me, but you should look at this source code, it contains your answer :) JC Private _ChangeWatcher As FileSystemWatcher Private Sub InitWatcher() _ChangeWatcher = New System.IO.FileSystemWatcher() AddHandler _ChangeWatcher.Changed, AddressOf Watcher_Changed With _ChangeWatcher .BeginInit() .EnableRaisingEvents = True .IncludeSubdirectories = False .NotifyFilter = IO.NotifyFilters.LastWrite .Path = _FolderToMonitor .Filter = _FileName .EndInit() End With End Sub ''' ----------------------------------------------------------------------------- ''' <summary> ''' Called when the FileSystemWatcher detects a change (matching ''' the NotifyFilter) on the specified file. In this case, the handler ''' will be called when a file is created or updated. ''' </summary> ''' <remarks> ''' We cannot rely on the ChangeType, it is always CHANGED, ''' even when the file was created. Luckily, it has no impact. ''' </remarks> ''' ----------------------------------------------------------------------------- Private Sub Watcher_Changed(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) SyncLock Me If String.Compare(e.Name, _
Can you show the Initialization() method ?
Jean-Christophe Grégoire
If you need a unique number that is always the same when regenerated, you can always ask a hashcode on a unique string, as long as you manage to create the same string. Here is a modified version of the previous answer to illustrate the idea: Guid guid = new Guid(); guid = Guid.NewGuid(); string unique = guid.ToString(); int uniqueInt = unique.GetHashCode();
Jean-Christophe Grégoire