Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

mikanu

@mikanu
About
Posts
62
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • How do you create 2 random values [modified]
    M mikanu

    The correct way to do that is to create an instance of the Random class and then call one of the following methods: - Next(Int32 max) // will return a random number smaller than _max_ - NextByte() // will return a random byte (between 0 and 255) - NextDouble() // will return a random number between 0.0 and 1.0 Here's a code sample which will generate two random numbers, a and b, between 0 and 10

    Random rnd = new Random();
    int a = rnd.Next(10);
    int b = rng.Next(10);

    ---- <a href="www.mdinescu.com">www.mdinescu.com</a>

    C# question lounge

  • Visual Fox pro database to Sql Server
    M mikanu

    In order to access FoxPro databases you have to use the OleDB data access classes. If you are familiar with the SQLClient namespace, all you need is to basically replace SQL with Ole in whenever you use anything like: SQLDBConnection --> OleDbConnection. You do have to pay attention when you create the connection string for your database. The rest should be pretty straight forward if you have the odbc drivers installed properly for the fox pro database that you intend to use. Good luck!

    ---- www.digitalGetto.com

    C# database csharp sql-server com sysadmin

  • How to specify an event handler
    M mikanu

    I've always used the first method (using the New operator to instantiate a new delegate that will handle the event). You can alway declare a variable that holds the reference to the event handler in advance and then use that as your handler like so:
    EventHandler eh; eh = **New** EventHandler(SomeEventHandler); a.SomeEvent += eh;
    this way you could later detach the event handler too, like so: a.SomeEvent -= eh; _//(as long as eh still references your event handler!)_
    The second way seems to be a shortcut for the first (in which the compiler automatically generates the code that instantiated the delegate and than passes it your function). Hope this helps, but your best bet is to do some reading on delegates and event handlers in C#.

    ---- www.digitalGetto.com

    C# question csharp visual-studio com tutorial

  • C# Class Library - Updating Application Settings
    M mikanu

    you can always create an XmlDocument object and load up the settings file and make the changes manually. For web applications I know there's a way to change the config file but I'm not sure if it will work in your case. Here's how I did it for my web application: Configuration config = ConfigurationManager.OpenExeConfiguration(""); ConfigurationSection section = config.Sections["connectionStrings"]; // you can use the section information here such as // section.SectionInformation.UnprotectSection(); // then make sure to save the changes to the file config.Save(); and that's it

    ---- www.digitalGetto.com

    C# csharp question visual-studio com tools

  • How to send a message in TCP/IP?
    M mikanu

    The structure that you are trying to send.. is that something you made? Is the receiving end a program that you're writing? If not, what format does it expect the data to be in? Serialization/Deserialization is a process. That's all. There is nothing magic involved. You can always write your own functions to serialize and deserialize data. Here's an example of a simple structure that is serialized into a byte array:

    struct myStruct
    {
    int iValue; // integer value
    string strValue; // zero terminated string

    public myStruct(byte\[\] sourceArray)
    {
        int k;
        
        if(sourceArray.Length > 2)
        {
            // reconstruct int value from lo byte and hi byte
            this.iValue = sourceArray\[0\] + sourceArray\[1\] \* 256;
        
            // reconstruct string value
            this.strValue = "";
            k = 2;
            while(sourceArray\[k\]!=0 && k\> 8) & 0xFF;  // hi byte
        
        // save the string value
        k = 0;
        while(k < this.strValue.Length)
           tmpArray\[k + 2\] = this.strValue.ToCharArray()\[k++\];
        
        return tmpArray;
    }
    

    }

    // ...
    // test code

    byte[] t;
    myStruct A;
    myStruct B;

    A = new myStruct();
    A.iValue = 567;
    A.strValue = "test string";

    t = A.Serialize(); // t = serialized array of the strucutre
    B = new myStruct(t); // B = a copy of A, constructed by deserializing t

    obviously, once you serialize your structure into an array you can send it over TCP/IP using a WinSock ---- www.digitalGetto.com

    Managed C++/CLI json tutorial question

  • How to send a message in TCP/IP?
    M mikanu

    say what?!?! can you try and explain your problem a little bit. What do you mean by the other side is unknown? And, which part of sending over TCP/IP don't you understand? Please, be a little more specific about what you are trying to accomplish. It will help us give you the right answer. ---- www.digitalGetto.com

    Managed C++/CLI json tutorial question

  • override onpaint
    M mikanu

    I'm not 100% sure but I think if you want to use the standard doublebuffering that .NET 2.0 GDI+ is offering you have to implement some other functions to support it. Make sure you find a good article on that. It's not trivial at first but once you grasp the fundamentals it should be straight forwards. Also, did you mention using the Compact Framework?! That may be the reason. Google for an example of how to implement double buffering in C# with .NET 1.0/1.1... that is not using the .SetStyle and ControlStyles.DoubleBuffer. Good luck ---- www.digitalGetto.com

    C# tutorial question

  • override onpaint
    M mikanu

    In order to reduce flickering you may have to use a technique which is commonly reffered to double-buffering. What that means is that you create graphics context in the background and draw there. When you're done, you 'swap' the two graphics contexts. What that means is that you basically copy the back buffer graphics context's contents to the active graphics context. A quick search for double buffering will most likely give you all the information that you need. ---- www.digitalGetto.com

    C# tutorial question

  • Tiling an image in a PictureBox
    M mikanu

    I think your best bet is to override to override the OnPaint and add custom code to render the image tiled inside the picturebox. ---- www.digitalGetto.com

    C# help

  • Hide application from process list?
    M mikanu

    I don't know how the rest of this community feels about DRM software but I personally hate it. It seems unethical and the companies that promote such software should be sued and fined.. ---- www.digitalGetto.com

    C# question help

  • Graph to image
    M mikanu

    The only difference that I could think of it that you dispose of the Graphics object in the CreateBitmap function whereas I created the MemoryStream before disposing the Graphics object. Give that a try.. I don't have a lot of time on my hands right now to test, but I'd be intereseted to know if that fixes it. Miky ---- www.digitalGetto.com

    C# graphics question database data-structures

  • Graph to image
    M mikanu

    I don't know what is not working in your application but here is code that I wrote to verify your concept and it all works. To me, the problem is in your CreateBitmap() function. To test the following code, create a new C# Windows Apllication. Drag and Drop two picture boxes on your form. Then paste this code as your Form Load event handler:

            private void Form1_Load(object sender, EventArgs e)
            {
                MemoryStream memStream = new MemoryStream();
                byte[] myBytes;
    
                using (Bitmap bmp = new Bitmap(50, 50))
                using (Graphics grfx = Graphics.FromImage(bmp))
                {
                    grfx.FillRectangle(Brushes.Red, new Rectangle(0, 0, 50, 50));
                    bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Bmp);
                    myBytes = new byte[memStream.Length];
                    memStream.Position = 0;
                    memStream.Read(myBytes, 0, (int)memStream.Length);
                    /* uncomment these lines to draw three white pixels on the second pictureBox */
                    /*
                    myBytes[101] = 255;
                    myBytes[102] = 255;
                    myBytes[103] = 255;
                    myBytes[506] = 255;
                    myBytes[507] = 255;
                    myBytes[508] = 255;
                    myBytes[910] = 255;
                    myBytes[911] = 255;
                    myBytes[912] = 255;
                    */
                    pictureBox1.Image = Image.FromStream(memStream);
                    pictureBox2.Image = Image.FromStream(new MemoryStream(myBytes));
                }
            }
    

    *** Portion of the code above is taken from the post below[^] ---- www.digitalGetto.com -- modified at 12:38 Thursday 22nd June, 2006

    C# graphics question database data-structures

  • How to know if the image is valid
    M mikanu

    What kind of image are you using (what format). Also, did you write the other application that sits on the other computer and sends the images over MSComm?! If so, I would add a checksum to every transmission and check that first, before displaying the image. This would tell you if something got corrupted on the way.. ---- www.digitalGetto.com

    Visual Basic help tutorial career

  • Securing a SQL Connection string [modified]
    M mikanu

    As I'm sure you know, there is no such thing as perfect security. In most cases all you need to do is figure out your target audience and what level of security will sufice for your purposes. It usually take to figure out something that will keep *most* hackers out. This is a first and simple step you could take to further secure your connection strings. Encrypt them and instead of storing the key as a string in your code, obfuscate it a little bit. I'm going to give you a simple example of what that means but you can derive and go nuts with it. let's say you have the following key "mypass123". Dim i As Integer ' A counter Dim str(9) As Byte ' This array will store the ASCII codes of the characters in the key Dim keyLength As Integer ' This will store the keyLength Dim keyString As String ' Variable used to store the key at the end, as a string str(0) = 109 ' ASCII code for "m" str(1) = 121 ' ASCII code for "y" str(2) = 112 ' ASCII code for "p" str(3) = 97 ' ASCII code for "a" str(4) = 115 ' ASCII code for "s" str(5) = 115 ' ASCII code for "s" str(6) = 49 ' ASCII code for "1" str(7) = 50 ' ASCII code for "2" str(8) = 51 ' ASCII code for "3" keyLength = 9 ' manually specify the length of the key ' Load keyString with the key, by appending the characters of the key keyString = "" For i = 0 To keyLength - 1 keyString = keyString + Chr(str(i)) Next i ' Now you can use keyString as the key to unlock your connection string
    obviously you can improve the method of obfuscation even further. Here's an example: str(0) = 109 ' ASCII code for "m" str(1) = str(0) + 12 ' ASCII code for "y" str(2) = str(1) - 9 ' ASCII code for "p" str(3) = str(2) - 15 ' ASCII code for "a" str(4) = str(2) + 3 ' ASCII code for "s" str(5) = str(4) ' ASCII code for "s" str(6) = 49 ' ASCII code for "1" str(7) = str(6) + 1 ' ASCII code for "2" str(8) = str(7) + 1 ' ASCII code for "3"
    ---- www.digitalGetto.com

    Visual Basic question database sql-server sysadmin windows-admin

  • Graph to image
    M mikanu

    I'd say the problem is in the way you are creating the bitmap, and not how you save it into the MemoryStream. Josh is right, about not saving to a file but from your post I understand that it is not your intention to save to a file but rather to store the image bytes in a SQL database. I think the problem is in the CreateBitmap() function. I suspect it has to do with the fact that you create a graphics context from a bitmap that is empty. Than you draw to the graphics object but then dispose of it before saving. I'm not sure if that is what's going on but before you try saving it, draw it on a canvas on the screen to make sure the bitmap is properly created by CreateBitmap() ---- www.digitalGetto.com

    C# graphics question database data-structures

  • XML DOM - Attributes
    M mikanu

    You should be able to just use the collection of XMLAttributes as an array. So you code becoes something like this:
    Set objAttributes = objDOMNode.Attributes If objAttributes.Length > 0 Then // this will give you the first attribute Set objAttributeNode = objAttributes(0) tvwElement.Tag = objAttributeNode.nodeValue End If

    another option is to iterate through the collection of attributes and get each one of them, and append to the tree view.
    Set objAttributes = objDOMNode.Attributes If objAttributes.Length > 0 Then // This will itterate through all attributes For Each objAttributeNode in objAttributes // Use the attribute here to maybe add it to the tree view cointrol Next End If

    ---- www.digitalGetto.com

    Visual Basic html xml question

  • Graph to image
    M mikanu

    Hey there, I think there are a few problems in your code but I'm not 100% sure. First of all, your sample here doesn't really draw anyhting on the bitmap so - it should be black. Second of all, if you want to save the bitmap you will most likely need a FileStream, not a MemoryStream. The MemoryStream is just an in-memory stream. It will not be persisted anywhere. Maybe if you provide a bit more of your code here we'll be able to help out. Cheers ---- www.digitalGetto.com

    C# graphics question database data-structures

  • How can I format a richTextBox?
    M mikanu

    Well, when I said the method was not the most efficient I meant that for large texts it will most likely be rather slow. Depending on your needs you may or may not want to put in the extra effort to look for/implement more efficient algorithms. The performance hit of the method shown is due to the fact that it reads each character in the text. That is time consuming. A first optimization is to combine looking for BOLD tags with looking for ITALIC tags. That is, to use the same loop to do both. That way, you cut the time approximately in half. Another option you may consider is using unsafe code (pointers) to loop through the text. Yet another possibility is to use regular expressions to perform the search and replace. As far as the other problem goes (the code not replacing the tags), that is rather strange. I've tested the code before posting it here and it worked. Can you give me more details as to how it fails?! ---- www.digitalGetto.com

    C# question help

  • How can I format a richTextBox?
    M mikanu

    Well, if I understand correctly what you're trying to do should be as easy as parsing the text in the richTextBox control and looking for the <b> and <i> tags. The easiest (not the most efficient) way to do this is to do a two-pass parse of the text. First for the BOLD tags and second for the ITALIC text. Whenever you run into an open BOLD tag, increment boldCount variable and store the position. Then remove the tag from the text. Whenever you run into a close BOLD tag, decrement boldCount, and remove the colsing tag from the text. When boldCount = 0, select the text starting at the recorded position and then set it's bold property to TRUE. Keep going until the end of the text. Repeat for the ITALIC tags. Here is an example that does bold tags. Modifying this code to do italic text is trivial so it wasn't included here.. Hope this helps and don't forget to visit digitalGetto

        private void ParseBoldText(RichTextBox tb)
        {
            int boldCount = 0;
            int lastBoldStartPosition = 0;
            int currentPosition = 0;
    
            while (currentPosition < tb.Text.Length - 3)
            {
                if (tb.Text.Substring(currentPosition, 3) == "<b>")
                {
                    if(boldCount == 0)
                        lastBoldStartPosition = currentPosition;
                    boldCount++;
                }
                if (tb.Text.Substring(currentPosition, 4) == "</b>")
                {
                    boldCount--;
                    if (boldCount == 0)
                    {
                        tb.Select(lastBoldStartPosition + 3, currentPosition - lastBoldStartPosition - 3);
                        tb.SelectionFont = new Font(tb.SelectionFont.FontFamily, tb.SelectionFont.Size, tb.SelectionFont.Style | FontStyle.Bold);
                    }
                }
                currentPosition += 1;
            }
                                   
            //clean the <B> tags, carefulf to use the RTF property instead of TEXT property !!!!
            tb.Rtf = tb.Rtf.Replace("<b>", "");
            tb.Rtf = tb.Rtf.Replace("</b>", "");
        }
    

    ---- www.digitalGetto.com -- modified at 18:07 Tuesday 20th June, 2006

    C# question help

  • Online Booking
    M mikanu

    What exactly is your question? What are you trying to do? ---- www.digitalGetto.com

    Visual Basic help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups