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
D

dnewmon

@dnewmon
About
Posts
12
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • DateTime Range
    D dnewmon

    Ok, well you could try something like:

    DateTime dtStart = new DateTime(2005, 1, 1);
    DateTime dtEnd = new DateTime(2005, 1, 30);
    DateTime dtCurrent = dtStart;

    while (dtCurrent < dtEnd)
    {
    double dDays;
    if (dtCurrent.DayOfWeek != DayOfWeek.Sunday)
    dDays = 6.0 - (double)dtCurrent.DayOfWeek;
    else if ((dtCurrent.Day + 6) <= dtEnd.Day)
    dDays = 6.0;
    else
    dDays = dtEnd.Day - dtCurrent.Day;

    Console.Write(dtCurrent + " - ");
    DateTime dtEndOfWeek = dtCurrent.AddDays(dDays);
    Console.WriteLine(dtEndOfWeek);
    dtCurrent = dtEndOfWeek.AddDays(1.0);
    

    }

    David

    C# tutorial question

  • Proccess Comunication
    D dnewmon

    What programming language are we talking about here? .NET Framework: Sockets are fairly easy C/C++: Pipes, Mailslots, DDE or Network DDE are all possible SendMessage() can send 8 bytes per call or as much as you want/need with WM_COPYDATA. I don't know about performance on SendMessage(), but you could implement it easy enough. David

    IT & Infrastructure question

  • Having trouble with pInvoke, weird behavior.
    D dnewmon

    Paste some C/C++ source code about the function and the C# [DllImport] method. The problem is probably the fact that the exported function is decorated. If you know nothing about C/C++, your in for some confusion. David

    .NET (Core and Framework) csharp c++ winforms question

  • having a long menu not taking all the screen height
    D dnewmon

    Allow the menu to close as normal when the arrows are selected, update the items, and make it appear in the same location again. If you added the context menu to the control using the "ContextMenu" Property create a delegate for the MouseDown event and note the location of the mouse when the right mouse button is clicked. Update the menu items, then call: myCtrl.ContextMenu.Show(myCtrl, savedX, savedY); David

    C# css announcement

  • typedef in c#
    D dnewmon

    Well the idea is: Car car = someObj as Car; Boat boat = someObj as Boat; Plane plane = someObj as Plane; if (car != null) { } else if (boat != null) { } else if (plane != null) { } The assumption is that your testing classes on the same level in the class hierarchy. If your not testing classes on the same level, then the difference between is and as matters. But you could also write your if-else statement so that it tests the more specific class types to the more broad class types.... lol Anyways, David

    C# question csharp

  • Is it possible to remove existing graphics from an image?
    D dnewmon

    You have at least 2 solutions: 1. Create a class that extends PictureBox (or Control if you get adventurous) and override OnPaint(). 2. Keep a copy of the image in memory. I think the 1st option is the better choice because it opens the possibility for code-reuse and uses less memory. Example:

    public class PictureSelectionBox : PictureBox
    {
    private Rectangle selectionRect;
    private Pen selectionPen;

    public Rectangle CurrentSelection
    {
    get { return this.selectionRect; }
    set
    {
    this.selectionRect = value;
    this.Refresh();
    }
    }

    public Pen SelectionPen
    {
    get { return this.selectionPen; }
    set
    {
    this.selectionPen = value;
    this.Refresh();
    }
    }

    protected override void OnPaint(PaintEventArgs e)
    {
    base.OnPaint(e);

     if (this.selectionPen != null &&
         this.selectionRect.Width != 0 &&
         this.selectionRect.Height != 0)
     {
         e.Graphics.DrawRectangle(this.selectionPen, this.selectionRect);
     }
    

    }

    public void CommitSelection()
    {
    Graphics g = Graphics.FromImage(base.Image);
    g.DrawRectangle(this.selectionPen, this.selectionRect);
    g.Dispose();

     this.CurrentSelection = new Rectangle(0, 0, 0, 0);
     this.Refresh();
    

    }
    }

    You could even override the OnMouseDown, OnMouseMove, and OnMouseUp events in the derived class to allow the user to make his/her selection. You better watch out with the use of Refresh() doing this though because you'll get some ugly flickering. I'd either [DllImport] InvalidateRect() or something like:

    Graphics g = this.CreateGraphics();
    OnPaint(new PaintEventArgs(g, this.ClientRectangle));
    g.Dispose();

    Enjoy, David

    C# graphics help question

  • DateTime Range
    D dnewmon

    First Row Differences:
    1-1-05, 1-2-05 = 1 Day
    1-2-05, 1-9-05 = 7 Days
    1-9-05, 1-16-05 = 7 Days
    1-16-05, 1-23-05 = 7 Days

    Second Row Differences:
    1-1-05, 1-8-05 = 7 Days
    1-8-05, 1-15-05 = 7 Days
    1-15-05, 1-22-05 = 7 Days
    1-22-05, 1-24-05 = 2 Days

    I don't see any patterns in the differences here, so what exactly do you want again? What do you mean by "divide the date range into it" ? What do you want to do? Are looking for every Sunday/Saturday in the month? The work-week days? Display a calender to the screen? David

    C# tutorial question

  • Disabling MenuItems
    D dnewmon

    Are you talking about menu items with CheckBox's ? Something this simple might help: menuItem3.Enabled = (menuItem1.Checked && menuItem2.Checked && ...); Enjoy, David

    C# question tutorial

  • Security permisions for unmanaged code in .Net Applet
    D dnewmon

    I just figured out a way to do this: bmpCanvas = new Bitmap(320, 240, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(bmpCanvas); g.Clear(Color.White); g.FillRectangle(new SolidBrush(Color.Red), 0, 0, 200, 200); g.FillEllipse(new SolidBrush(Color.FromArgb(255, 0, 0, 0)), 0, 0, 200, 200); g.Dispose(); bmpCanvas.MakeTransparent(Color.FromArgb(255, 0, 0, 0)); The ellipse is an "erased" region and considered transparent. I tried using Color.Transparent instead of Color.FromArgb(255, 0, 0, 0) but had no luck. NOTE: The MakeTransparent(...) call has to be made every time you erase a region. Enjoy, David

    .NET (Core and Framework) csharp html database sql-server graphics

  • Want to know path of .exe file
    D dnewmon

    I have one thing to say: System.Windows.Forms.Application.ExecutablePath

    C# com question

  • What is the equivalent of LOBYTE and HIBYTE in C#?
    D dnewmon

    Well the C++ macros are defined as follows: #define MAKEWORD(a, b) ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8)) #define MAKELONG(a, b) ((LONG)(((WORD)((DWORD_PTR)(a) & 0xffff)) | ((DWORD)((WORD)((DWORD_PTR)(b) & 0xffff))) << 16)) #define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xffff)) #define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16)) #define LOBYTE(w) ((BYTE)((DWORD_PTR)(w) & 0xff)) #define HIBYTE(w) ((BYTE)((DWORD_PTR)(w) >> 8)) Looks ugly and complex but its not as hard as it looks. Most of the casting can be removed actually. C++ macros don't have parameter types so their casting to ensure all the integers are the correct size before performing the math on them. I used the UInt32, UInt16 and Byte types to be explicit. So I created the C# equivalent: class ByteAccess { public static UInt32 MakeLong(UInt16 high, UInt16 low) { return ((UInt32)low & 0xFFFF) | (((UInt32)high & 0xFFFF) << 16); } public static UInt16 MakeWord(byte high, byte low) { return (UInt16)(((UInt32)low & 0xFF) | ((UInt32)high & 0xFF) << 8); } public static UInt16 LoWord(UInt32 nValue) { return (UInt16)(nValue & 0xFFFF); } public static UInt16 HiWord(UInt32 nValue) { return (UInt16)(nValue >> 16); } public static Byte LoByte(UInt16 nValue) { return (Byte)(nValue & 0xFF); } public static Byte HiByte(UInt16 nValue) { return (Byte)(nValue >> 8); } } Enjoy. David

    C# question csharp help

  • Security permisions for unmanaged code in .Net Applet
    D dnewmon

    The only way to do what you want here without using your unmanaged DLL is to create a Bitmap object and draw to it. Example: private Bitmap bmpCanvas; OnLoad(...) { bmpCanvas = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); } OnResize(...) { bmpCanvas = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); } OnDrawRect(...) { Graphics g = Graphics.FromImage(bmpCanvas); g.DrawRectangle(...); g.Dispose(); } OnPaint(object sender, PaintEventArgs pe) { pe.Graphics.DrawImage(bmpCanvas, 0, 0); } After this has been implemented you can start streaming fairly easily: // Pre-Buffer alittle maybe: MemoryStream stream = new MemoryStream(bmpCanvas.Width * cmpCanvas.Height * 3); // Stream as PNG (loss-less and has good compression): bmpCanvas.SaveImage(stream, ImageFormat.Png); You can then call stream.GetBuffer() and use stream.Length to send the data. You might want to ensure the user is complete and dispose of the Bitmap to reduce the memory footprint.

    .NET (Core and Framework) csharp html database sql-server graphics
  • Login

  • Don't have an account? Register

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