snarfblam
Leaders-
Posts
2156 -
Joined
-
Last visited
-
Days Won
2
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by snarfblam
-
One possiblility would be to examine the ActiveControl property and act based on that... Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If ActiveControl Is TextBox1 Then 'You probably want to do nothing here Else If e.KeyCode = Keys.W Then 'Do things here End If End If End Sub You could also set the KeyPreview property when a TextBox gets or loses focus... Private Sub TextBox1_Enter(ByVal sender As System.Object, ByVal e As em.EventArgs) Handles TextBox1.Enter KeyPreview = False End Sub Private Sub TextBox1_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Leave KeyPreview = True End Sub
-
iNSErting an image into xml document
snarfblam replied to a1jit's topic in Database / XML / Reporting
You are trying to store actual image data as opposed to an image name? This makes a world of difference. IMHO, It certainly wouldn't make much sense to store image data as an attribute. You should probably put the image data as the content of the Image element. XML isn't exactly ideal for binary data storage. Binary data and the XML format don't play together nicely, so the data has to be formatted, which tends to cause bloat. The way that Visual Studio stores binary data in XML files is to store hexidecimal values. If the file is saved as Unicode this could as much as quadrouple the size of the binary data, and if the file is ASCII, it would double the size of the data. Typical binary data would probably look something like the following: <[color=DarkRed]SomeXmlTags[/color]> <[color=DarkRed]Image [/color][color=DarkOrange]Name[/color]=[color=Blue]"Cowabunga.bmp"[/color]> [color=Blue] D1C5A4F8B7E1C3B4E6A0F9B0C0E3A4B5F3C2A3 E1C5H8I9D6D3E1N400M1E5S7S7A4G1E2!5B8F0 C1A9E5B8F5C8A7E7C0F0A1E2B1F0C5A3E2B4A5 D8W6F9B5C7D1A5W2B5C4F0D1A4W2F6B5C3B2A4 D2A4W8A6W5D7B4C5D4A1W0B1F2C1D0A1A1A4B1 C0B6I5N4A8R5Y600I8S400D2A400B4O1M4B3A6 F4C6B7C8F9B4F1A3C5D2A6W4C7B5F2A3D6W9B5 C1D5A4W0B1C2F3D5A2W2A1A0B2A1C4F5A2[/color] </[color=DarkRed]Image[/color]> </[color=DarkRed]SomeXmlTags[/color]> [/Code] When the XML is obtained, the binary data can be extracted to a byte array, which can be used to create a memory stream which can be passed to the System.Drawing.Bitmap constructor. I'm not positive that this is what you are after. It almost sounds like you want someone to download an XML file, open it with IE or Visual Studio or whatever, and have an image show up, but that can't really be done. -
By default the KeyPress event only fires for the control that has focus, which will never be the form if the form has child controls. You should set the form's KeyPreview property to True. This causes the form to intercept all keyboard input and process it before it is sent to child controls, which should be all you need to do to make your program work.
-
My suggestion would be to change your form to a UserControl. A UserControl is very similar to a form, but instead of floating around the desktop it has to be put on another form. This seems to be exactly what you need.
-
What? I'm not sure whether or not you understood, but the point I was making to mskeel was that the * operator is a character. Also, I opened up C++ 2005 and tried public: static Form2^ childform; (which is the equivalent to public: static Form2* childform; in C++ 2003) and got no errors. I would have to say that the error is being caused by some code that you didn't post. I know you said that the includes were right, but that looks to be the most likely problem.
-
I've checked briefly in the options and didn't see it, but there might an option to show these files (I hope so). In C# they are visible by default. You click the "+" next to the form file and it expands to show the resource and designer code files associated with the form's code file. It can be really useful to get at the designer code sometimes, so I certainly hope that there is some way to get access to it other than finding it yourself with explorer.
-
If the file is password protected then not only should the password be protected, but the entire file should be encrypted. Look in the System.Security.Cryptography namespace. There are a few different encryption streams in there. I would strongly suggest that the entire file be run through an encryption stream. You might want to hash the user's password and use that as the encryption key. Then you won't have to store the password in the file. If they give the right password, the file will be decrypted. If not, the file will fail to decrypt and an exception will be thrown.
-
The correct term, I suppose, would be "class scope." This is a problem I used to have before I really got the hang of object-oriented programming. I understood the object-oriented concepts but didn't know the different ways that I could take advantage of them to make life easier. To cut down on the clutter of a large number of variables all declared in one class takes a combination of solutions, most of which are manifestations of object-oriented programming concepts. One big thing that reduces code clutter (at least in my programs) is to extend controls through inheritance rather than extarnal machanisms, or, in other words, to inherit a control to add functionality to it rather than adding variables and functions to the form the control will go on. For instance, if you have a button the user clicks to bring up a date dialog, instead of adding a click handler function, a variable to store the date, code to display the dialog, etc., create a DateButton class that derives from the Button class. Have all the interation code (dialog popup, button's text) put in the DateButton file. Create a Date property and a DateChanged event and it is ready to be dropped on your form, fully functional while adding very little code to the form's code file. Another suggestion would be to create structures or classes to hold related groups of data. Instead of having variables UserName, UserID, UserIP, UserIsAdmin, etc., you could create a structure to store all that data in and have only a single variable in your form's code.
-
Yes, * is an operator. It is also an ASCII/Unicode character. The term character has a definition beyond that of programming data types. A text file/code file is actually a sequence of characters written to the hard disk, no? All text, even beyond the realm of all that is digital, is ultimately composed of characters. Besides, why the need to split hairs? Even if I had said something that didn't entirely make sense, you got my meaning, no?
-
A search on Google yielded this as the first result. The tutorial implements the ICustomTypeDescriptor interface to customize what is shown in the PropertyGrid. Depending on your needs, it might be easier to create a class that exposes the property you need to be edited. class EditableItem { // Constructor public EditableItem(int width, int height, int etCetera){ _Width = width; _Height = height; _EtCetera = etCetera; } // Expose data to edit as properties int _Height; public int Height{ get{ return _Height;} set {_Height = value;} } int _Width; public int Width{ get{ return _Width;} set {_Width = value;} } int _EtCetera; public int EtCetera{ get{ return _EtCetera;} set {_EtCetera = value;} } } public void EditItem(int index1, int index2) { // Create an object with the data to edit EditableItem i = new EditableItem( Heights[index1, index2], Widths[index1, index2], EtCeteras[index1, index2]); // Present the user with the data in the property grid MyPropertyGrid.SelectedObject = i; // At some point you will need to save the previously selected item's data // back to the arrays. A good time to do this would be immediately before // a new item is selected. } Public Class EditableItem 'Constructor Public Sub New (width As Integer, height As Integer, etCetera As Integer) _Width = width _Height = height _EtCetera = etCetera End Sub 'Expose data to edit as properties Dim _Width As Integer Property Width() As Integer Get Return _Width End Get Set(ByVal value As Integer) _Width = value End Set End Property Dim _Height As Integer Property Height() As Integer Get Return _Height End Get Set(ByVal value As Integer) _Height = value End Set End Property Dim _EtCetera As Integer Property EtCetera() As Integer Get Return _EtCetera End Get Set(ByVal value As Integer) _EtCetera = value End Set End Property End Class Public Sub EditItem(ByVal index1 As Integer, ByVal index2 As Integer) 'Create an object with the data to edit Dim i As New EditableItem( _ Heights(index1, index2), _ Widths(index1, index2), _ EtCeteras(index1, index2)) 'Present the user with the data in the property grid MyPropertyGrid.SelectedObject = i 'At some point you will need to save the previously selected item's data 'back to the arrays. A good time to do this would be immediately before 'a new item is selected. End Sub
-
How do I read binary files ?
snarfblam replied to ndaigneault's topic in Directory / File IO / Registry
Would the classes you need be found in IOStream.h? This is something that you should be finding in Microsoft's reference material, or reference on C++ standard libraries. -
Can anyone point me in the right direction?
snarfblam replied to vbMarkO's topic in Graphics and Multimedia
The best approach would probably be to code this from the ground up unless you can find third party controls. This would mean, as Nate indicated, that you will have to get your hands dirty and learn about not only Graphics object and Bitmaps but also control painting. There are plenty of tutorials around on these subjects. Another option would be to build controls out of other controls; construct your thumbnail and filmstrip controls out of pictureboxes, lablels, and panels. Doing this, though, would involve an understanding of dynamic control creation. There are also tutorials on this. -
Mike's suggestion is probably the best if you know which overload you want ahead of time. Also, in both code listings you are creating a null reference to an object array and then assign values to its elements. I don't know if that was the actual code you had or if you retyped it and made a mistake, but replace Dim ob As Object() = Nothing ob(0) = DirectCast(DateTime.Now().ToString(), Object with 'Use the (New Type(ubound) {}) syntax to create an array. 'Make sure you have the right number of elements, in this case 'one for one parameter Dim ob As Object() = New Object(0) {} 'This is a "narrowing" conversion. You don't need to explicitly convert anything 'to an object because everything already is an object. ob(0) = DateTime.Now().ToString() or 'Easier syntax: Dim Variable As Type() = {item, item, item...} Dim ob As Object() = {DateTime.Now().ToString()}
-
I ran into a very similar problem recently. The AutoScrollPosition property is pretty quirky. When you get the AutoScrollPosition is returns how much the view has moved, i.e. {10, 20} would be scrolled right ten and down twenty. When you set it, you need to specify how far the controls should be moved. If you are scrolled ten right and twenty down, the controls have moved ten left and twenty up on the screen, which means that you would want to set AutoScrollPosition to {-10, -20} to set it to that same position. I'm guessing that this is a bug. I believe that the solution is to negate the value immediately before assigning it (if you want to think in terms of where the view port is... if you want to think in terms of how far the controls have moved, negate the value as soon as you obtain it). For example, to move the AutoScrollPosition down and right fifty pixels, you would use the following code: Dim View As Point = MyPanel.AutoScrollPosition View.X = -(View.X + 50) View.Y = -(View.Y + 50) MyPanel.AutoScrollPosition = View I didn't test that code, but something like that should do the trick.
-
How do you determine if an event has been assigned to a control
snarfblam replied to j2associates's topic in Windows Forms
VB event handling is a little different. In C#, events and delegates are treated exactly the same, where as VB has special syntax for events and hides the actual backing multicast delegate from the programmer. The VB RaiseEvent keyword automatically performs a check for null before invoking the delegate (in C# this must be done explicitly), but provides no mechanism to see if the event is wired as far as I know. -
I beleive that they are still working on or discussing a WinForms implementation in Mono. On the other hand, I don't see why it wouldn't work if you run a Windows emulator. Don't know if that would really be worth it though.
-
VS2005: how to display splash screen for few seconds
snarfblam replied to kaisersoze's topic in Windows Forms
What is the specific issue? Why does the same approach not work? -
How to execute javascripts on axwebbrowser?
snarfblam replied to ajaikumarr's topic in Windows Forms
It should work with any valid java-script code in the string. The easiest way to find out, though, is to try for yourself and see if it works. -
If you don't make the functions shared then you have to instantiate the object. Although the object would have no data, it still takes time and memory to instantiate the object. In reality it is only a few bytes and a small handful of CPU cycles for each pointless instantiation, but what it really does is make a mess of your code. [Vb] Public Class IsShared Public Shared Sub DoThings() End Sub End Class Public Class NotShared Public Sub DoThings() End Sub End Class Public Class Example Public Sub Demonstrate 'With the shared class we can directly call the sub IsShared.DoThings() 'With the not shared class, we have to write pointless code 'to instantiate an object. It takes twelve pointless bytes of RAM '(I believe) and time to allocate memory for these pointless bytes, 'and adds extra data to the stack for each function call, but the 'biggest problem is the extra code: Dim thing As New NotShared '<-- Right there thing.DoThings() End Sub End Class [/code] Either way, it isn't a big deal, but using instance functions where they really have nothing to do with an instance of an object just doesn't make sense.
-
You're going to have to write some code somewhere to manually re-order the nodes.
-
Your thread title is a little mis-leading. It's more like free e-books. To be honest, I didn't even notice the poster, and, assuming it was spam, I was ready to report this thread to a moderator.
-
Which version of C++ are you using? If it is version 8 (C++/CLI) then you need to use "handles" with .Net objects. Instead of using the * character for .Net references, you should use the ^ character. Microsoft made this change to represent the difference between a real pointer and a .Net object reference.
-
It is not a matter of functions and properties. It is a matter of whether or not you need an object oriented approach. A function can be static ("shared") if it does not need to access any fields (variables) within an object of the type the function belongs to. If the class exists only to house helper functions then you are using an un-object-oriented approach and chances are there are no fields to access and the functions should all be declared as Shared. If, though, you were to inherit from that class, you could benefit from having instance methods (not shared) in terms of polymorphic behavior, but on a utility class that most likely won't be of much use. In VB you can make the object uninstantiable by declaring a private default constructor. In C# this can be done by declaring the class as static.
-
You need to use the System.Drawing.ToolBoxBitmapAttribute class. Imports System.Drawing <ToolboxBitmap(GetType(MyTextBox), "NameOfResource")> _ Public Class MyTextBox '... End Class using System.Drawing; [ToolboxBitmap(typeof(MyTextBox), "NameOfResource")] public class MyTextBox { // ... } There are different overloads, but this is probably the best. You pass the name of the resource and an object type in your assembly so the constructor can find the assembly to extract the resouce. The name of the resource isn't going to be the same as the name of the file. Depending on how it is added to the project, the name varies. It might be a good idea to compile the program, then decompile it with Reflector to find the name of the resource, then add the attribute.