Jump to content
Xtreme .Net Talk

snarfblam

Leaders
  • Posts

    2156
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by snarfblam

  1. Uh... to be perfectly clear, I was recommending a solution that doesn't involve any controls at all except for a single control to host all your content. It sounds like you're still working on a solution that involves layering controls. One of the solutions I suggested was to use "pseudo-controls." Such a class would inherit the System.Component class instead of System.Windows.Forms.Control or System.Windows.Forms.UserControl. All pseudo-controls would be hosted within a single control that maintains a list of pseudo-controls and routes events as appropriate. This involves a little bit of re-inventing the wheel, duplicating many functions of the existing Control class, but you only have to implement those features you need. You would have a Paint event and an Invalidate function, and quite probably mouse events. You would have to convert coordinates from the host control's coordinates to the child control coordinates. Here's an example of what is probably to most complex case of converting between coordinates (code is untested): Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim transform As Drawing2D.Matrix = e.Graphics.Transform For Each child As PseudoControl In pcontrols If e.ClipRectangle.IntersectsWith(child.Bounds) Then [color="Green"]' Adjust graphic output to be relative to the child "control" (*)[/color] e.Graphics.TranslateTransform(child.Bounds.X, child.Bounds.Y) [color="Green"]' Restrict invalid rectangle to child's "client area"[/color] Dim localRect As Rectangle = e.ClipRectangle localRect.Intersect(child.Bounds) [color="Green"] ' Translate to child coordinates[/color] localRect.Offset(-child.Bounds.X, -child.Bounds.Y) [color="Green"] ' Let the child draw[/color] child.Paint(localRect, e.Graphics) [color="Green"] ' Restore the transformation matrix (*undo what we did above)[/color] e.Graphics.Transform = transform End If Next End Sub Other features (nested controls, focus, keyboard input) would be implemented only if needed. This isn't the only possible solution, and it is a lot of work and a bit advanced, but it is a solution that will be robust, efficient, re-usable, and will separate layout and rendering logic from all your other code. Whether you use this method or another is your call. Now, even if you get something set up involving layered controls, and get it to work consistently across multiple machines with different versions of Windows with different settings, I'm concerned that the graphic updates will be slow and flickery. Maybe this is okay. Maybe that doesn't matter for your program. I don't know. As far as your object instance error, you haven't posted the code that's throwing the error or explained when the error occurs. (When the form loads? When it resizes? When it paints?) But I'm guessing that you can probably make some sense of it if you use the debugging features available. Set a breakpoint on the problem function, or let the debugger break when the exception occurs. The hover over variables or use the Watch window to examine variables and properties and try to figure out what is going wrong. Is something set to null that you're not expecting? Why? Maybe a function is being called when you don't expect. Who knows? Exercise your debug muscle.
  2. What you're looking to do is, by design, not possible. You could probably fudge it by painting in a certain manner that isn't necessarily correct. For example, when your transparent control is invalidated, it can force a refresh of the underlying region of its parent, then do its own painting. Depending on exactly how you orchestrate it, it may or may not work. But even if you get it to work, you're not following the rules, and different versions of Windows and .NET aren't required to behave the same way in circumstances where somebody isn't following the rules. So even if you get it working on your machine, you could ship out the program and find that it doesn't work for 50% of the users. Or it might not work with the next version of Windows. Who knows? In WinFroms, each control has its own window, and what you want to do violates the principles of how windows interact. Every window is responsible for drawing itself and only itself. .NET's "transparent" controls are a special case where a window kindly asks its parent window to draw itself before the child draws its own content on top. That is a very simple level of cooperation between the two controls. What you need is much more complex. If Label2 needs to be drawn, first it needs the container to draw itself, then Label 2 and all other overlapping controls would have to draw themselves in order, based on Z-order, each window rendering text to parts of the screen it doesn't own. This level of cooperation between controls simply isn't supported in .NET. So how do you fully support transparent controls? That are different ways you can approach that. Maybe you don't even need controls at all. If all you need to do is draw overlapping text in a form, you can do that in the Form's paint event. If you're looking for a re-usable solution, I've personally had plenty of success with "pseudo-controls" similar to VB6's lightweight (i.e. windowless) controls. They can duplicate the most important aspects of a control (location and size, invalidation/painting, keyboard and mouse handling) and be implemented by either a control designed to host windowless control and route events as appropriate, or as components that handle events of the container and interpret the events as they apply to the windowless child. Without knowing why you need transparent labels, it's hard to recommend the most appropriate solution.
  3. How are you achieving transparency? Are you setting the BackColor to Transparent? Are you setting any style? What is the base class? Control? If you make a control transparent by setting the "Opaque" style and not clearing the background, you might see the behavior you're getting. If you set the "SupportsTransparentBackColor" style and use a transparent backcolor, it should work correctly. I'm a little curious as to why you are creating a transparent label when .NET labels already support transparency.
  4. Re: Extract icons from icl files Hi xyience. Welcome to the forum :). Just to let you know, when a thread is more than a month old, or when asking a new question, we prefer to create new threads with a link to the old one. If you haven't already, please give the Posting Guidelines a read. As to your question, are you having a problem extracting the icon, or creating the .ICO file?
  5. It's entirely a matter of taste. ControlChars.Tab and vbTab are both constants. ControlChars.Tab is a Char constant equal to a tab character. vbTab is a string constant that contains a single tab character. When you compile the program, references to constants are replaced with the constant value. Also, when you use a character with the & operator it is automatically converted to a string. In this case, the conversion probably happens at compile time. So these three lines of code should produce the same exact compiled code: Dim s As String = ControlChars.Tab Dim s As String = vbTab Dim s As String = ChrW(9) I would choose the second option because it is easy to read and involves less typing, but that's just like uh, my opinion man.
  6. Are you following some sort of tutorial or something? Have you tried to code it on your own?
  7. It looks like the ListBox isn't directly populated with the data but rather with DataRowView objects which the ListBox queries to get the data. You should start by looking at the DataRowView documentation on MSDN and see if there is a simple property or function you can call that gives you what you need. Your code will probably end up looking something like this For Each item in listbox1.Items Dim data As ???? = DirectCast(item, DataRowView).???? form2.listbox2.Items.Add(data) Next
  8. Of course. Please post the code you have so far and explain which step you are having trouble with or what aspect of the task you don't understand. That way we know exactly what you need help with.
  9. Re: Altering Button down state ("pressed") with key You could use a CheckBox control, setting the Appearance property to "Button." It will look like a normal button, but when the Checked property is set to true, the button will appear to be pressed in. You might want to set AutoCheck to false. Otherwise the button will toggle between pushed and raised when the user clicks on it.
  10. It would be easier to give helpful advice if you explain what you are doing a little better. Are you trying to encode text? Or read text with various encodings? Where is the text coming from or going to?
  11. Re: How to sort List of Buttons The Sort method comes in handy: Sub SortButtons() vKey.Sort(AddressOf SomeButtonCompareFunction) End Sub Function SomeButtonCompareFunction(ByVal A As Button, ByVal B As Button) As Integer ' You probably want to perform a string compare of the two button's names here. End Function
  12. I'll start by saying you really want to avoid variable names such as counter, counter2, temp, test, and j. These names don't tell me anything about what the variable actually stores, and they won't help you much if you need to go back and look at your own code down the road. What is counter counting? What does test test? I would rather look at a variable name like "numOfCharactersThatMatchBetweenTheBeginningOfTheStringAndTheEnd" than "counter". I spent some time sorting through your code I really just can't understand what it's trying to do. Like I said, I'm a little confused as to how you get from the input to the output. I don't understand the step-by-step process. Okay, it looks like the concept is that we would need to reverse and append part of the beginning of the string to create the palindrome. But wait... Where did that extra "i" come from? And now I'm confused about what the hyphens mean.
  13. I'm a little confused as to how you get from the input to the output. The code is also difficult to read. Comments are sparse and everything is shoved into a single function. I'd like to help, but I already have a headache. :)
  14. how to use AES Encryption in C#? what is the benifit of using AES 256 bit standard for encryption? Hope that helps :).
  15. Edit: Nevermind. Read ATMA's post on the other forum. It sounds like the best idea is to use the String.Trim function. You can specify a set of characters that you want trimmed, in this case carriage-return and line-feed. ' There are the line ending characters we don't want in our strings (LF and CR) Public Shared ReadOnly LineEndChars As Char() = {ChrW(10), ChrW(13)} ' This function removes line ending characters from a string Function Example(ByVal text As String) As String Return text.Trim(LineEndChars) End Function
  16. You're code is a bit hard to read. While that might sound nit-picky, and it's a subjective thing, when code is more readable, it is easier to understand and reason about it, especially at a glance. It also helps us help you. The documentation for Vector3 states that the fields are floats, not doubles. You either need to cast to float, or make sure that all of your variables are floats rather than doubles. Something like this should work. Velocity[a] = (new Vector3( Proximity.X != 0 ? [color="Blue"](float)([/color]Velocity[a].X + (1/(Influence * Proximity.X))[color="Blue"])[/color] : Velocity[a].X, Proximity.Y != 0 ? [color="Blue"](float)([/color]Velocity[a].Y + (1/(Influence * Proximity.Y))[color="Blue"])[/color] : Velocity[a].Y, Proximity.Z != 0 ? [color="Blue"](float)([/color]Velocity[a].Z + (1/(Influence * Proximity.Z))[color="Blue"])[/color] : Velocity[a].Z ));
  17. From what I understand the short answer is you can't do that. There are some workarounds, but I have no experience with these solutions. Apparently there are third-party COM components designed for calling native DLLs. You can also create your own COM wrapper with VB6 or .NET that you can then call from VBscript. One way or another you'll need a middle layer that can work with both VBscript and native code.
  18. What exactly are you doing with these usernames? It's virtually impossible to help you with a regex problem without seeing the regex expression you are using and the code that is using it.
  19. Are you talking about the z clipping plane? Or are you having a problem with the depth buffer? Maybe you should post an image depicting the problem, and the code you are using to set up the device.
  20. Grave-dig or not, it's a pretty pointless post. My guess is it's a bot that makes a seemingly innocuous post, hoping to sneak in under the radar, and later change the sig to include an ad. Best thing to do is just to use the "report post" button. It notifies the moderators, and somebody will be by to sweep it up.
  21. Well, first you need to be able to parse .doc files (at least, it sounds like you are dealing with .doc files). The simplest approach would be interop with office. Then you need to be able to search for the relevant data. If the resumes have a very consistent layout/format this might be simple. On the other hand, if you need to be able to handle any resume thrown at you, you would need to work out a heuristic to try and identify and extract the information needed. Which part are you having trouble with? Now, if you don't even know where to begin, it's probably not practical for you to try and tackle this. This calls for years of experience in programming, office interop, text parsing, regex, etc.
  22. No, you shouldn't need to create a delegate type. The code I posted should be all you need to raise your event. Here is a more complete listing: public partial class EFile_ComboBox : UserControl { public event EventHandler TextChanged; [Category("Appearance")] [Description("Specifies if a shadow should be draw for the button text.")] [DisplayName("Text")] [EditorBrowsable(EditorBrowsableState.Always), Browsable(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), Bindable(true)] public override string Text { get { return sText; } set { sText = value; this.Invalidate(); [color="Blue"] var evnt = TextChanged; if(evnt != null) evnt(this, EventArgs.Empty); [/color] } } private void TextBox_Validated(object sender, EventArgs e) { [color="Red"] // invoke UserControl event here if (this.TextChanged != null) this.TextChanged(sender, e);[/color] } } The code in blue I added, which raises the TextChanged event. The code in red I'm a bit confused about. It also raises the TextChanged event, but I don't see why you would raise this event anywhere except the Text property setter. If there is a reason the event needs to be raised from the TextBox_Validated method instead of the Text setter, then your code should work as-is, without my addition. Has the code you posted not been working as expected?
  23. I'm not clear on what you're asking. You want to raise the TextChanged event when the Text property is set? You already have code that raises the event. Just do the same in the Text setter. Or am I misunderstanding? public override string Text { get { return sText; } set { sText = value; this.Invalidate(); var evnt = TextChanged; if(evnt != null) evnt(this, EventArgs.Empty); } }
  24. Re: c# Capture Screen and Pixel Search Have you examined your process' and machine's actual memory usage when this error occurs? GDI and GDI+ seem to derive joy from throwing inexplicable OutOfMemoryExceptions when there is a completely unrelated problem. Your issue may not have anything to do with memory at all. Try using a different image format, or, if you are trying to access a resource, see if the same code works with an external file. If you're accessing a network drive, try a local drive. Maybe you can narrow it down. If you do have an actual memory leak, there are free profilers available, which are great for many things, including finding memory issues.
  25. The standard textbox does not support this feature. You might be able to do something like this with a rich text editor. Are the "components" supposed to be controls (e.g. clickable button) or placeholders for predefined values (in which case, why not use some sort of %tags%)?
×
×
  • Create New...