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
_

_Erik_

@_Erik_
About
Posts
297
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Strange problems with WaitForSingleObject Windows function
    _ _Erik_

    Yes, I wanted to avoid bothering them, but I guess I don't have any other option. Thank you very much.

    C# help security sales question learning

  • Strange problems with WaitForSingleObject Windows function
    _ _Erik_

    I forgot to say this in the original post, sorry for that, but the printer driver was also written by myself, that is why I am so puzzled. Anyways, testing with other printers makes no difference: it works fine everywhere I test it but in the customer's computers it does the same... nothing, not even errors... Thanks for the tip anyway, Eddy.

    C# help security sales question learning

  • Strange problems with WaitForSingleObject Windows function
    _ _Erik_

    I am having a really strange problem with a component designed to watch for the printer events: First of all, the component has been working like a charm for years in all of the computers in which I have tested and with several operating systems (Windows XP, Vista, 7 and 8.1), in 32 and 64 bits, and running as normal user and local admin as well. However, in the computers of my last customer (Windows 7 64 bits) it only works when running as local admin which is, of course, unacceptable. Before bothering the admins of my customer I would like to know if someone of you has any ideas about the issue, because I have to confess I am completely puzzled. Basically, the compoment starts a thread in which it invokes FindFirstPrinterChangeNotification, which returns a valid handle. Then it invokes WaitForSingleObject for that handle and here is where things get strange: in every other computer, as I said before, it receives and processes the signals perfectly, but in my customer's ones, unless run under local admin, it just stays waiting and receiving no signals no matter what the printer is doing. I mean it does nothing, not even errors. It just waits but the signal does never arrive. I have been reading through the MSDN documentation but I cannot find any plausible explanation: the printer is a local printer which prints to a file and, yes, WaitForSingleObject requires SYNCHRONIZE access right, which I think shouldn't be a big deal. I have not pasted code here because, as I said, it works like a charm in every other computer, so it must be a security configuration issue. Any ideas? Thank you very much.

    C# help security sales question learning

  • MQOTD
    _ _Erik_

    Riddick Easy peasy

    The Lounge com question

  • function call from an c++ dll in c#
    _ _Erik_

    This call is wrong:

    result = Fct2((IntPtr)2, data, 3);

    The first parameter should be a pointer to the address of memory which contains the size of the "data" array. Casting a literal "2" to IntPtr is telling the library that the length of the array is in the block of memory with the address 2. Try changing the function definition like this:

    [DllImport("Function.dll", CallingConvention = CallingConvention.Cdecl)]
    extern static int Fct3(ref int Size, byte[] data, int timeout);

    And call it like this:

    int dtLength = data.Length;
    result = Fct2(ref dtLength, data, 3);

    See you

    C# help csharp c++ debugging question

  • Classes inheritance and something that confuses me
    _ _Erik_

    Let's make a better example for this:

    class Employee
    {
    public string Name { get; set; }
    }

    class ContractEmployee : Employee
    {
    public object Contract { get; set; }
    }

    class Program
    {
    static void Main()
    {
    Employee e = new ContractEmployee();
    e.Name = "Ricky"; // No problem with this
    e.Contract = new object(); // Problem: this does not compile
    }
    }

    nstk wrote:

    which properties and methods does the object e has?

    e object, at runtime, has the properties and methods defined within ContractEmployee class, because it is the object you have created with new, so it has Name (inherited from Employee class), and Contract (defined within ContractEmployee). However, without any casting, from e object you will only be able to access those members defined within Employee class (Name property in this case), because it is the type you have used to declare the object. Why? Because e object is declared as Employee, and Employee does not define a member named Contract. Yes, e is a ContractEmployee instance and, yes, it has a Contract property, but the compiler does not know it. All the compiler knows is that e object is declared as Employee, so it allows you to access only the members defined in Employee class. So, if you want to access the Contract property of e object, in this case, you would need a previous casting operation:

    ((ContractEmployee)e).Contract = new object();

    // or

    ContractEmployee ce = (ContractEmployee)e;
    ce.Contract = new object();

    nstk wrote:

    how should I read this?

    Any ContractEmployee object is a Employee, always, so you can declare an Employee and instantiate a ContractEmployee, but not in the other direction, I mean, not all of the Employee objects have to be ContractEmployee.

    C# question csharp oop tutorial learning

  • The perfect teacher
    _ _Erik_

    Congratulations. You have found the main source of the content in hall of shame: shameful teachers.

    The Weird and The Wonderful csharp java visual-studio tutorial question

  • abstarct class basic question [modified]
    _ _Erik_

    Member 4282287 wrote:

    I need to access to proprieties, methods, etc of class

    That does not depend on how you create the objects, I mean, your Create method will not help you to achieve what you want. If you can access KM property of a D1 object which you have declared as its base class type (b in this case), you can becouse KM property is definied within the "b" class interface, but not becouse you have made such a strange Create method. So in your sample:

    b myClassAb = new D1();
    b newClassAb = myClassAb.Create();
    Console.WriteLine(newClassAb.KM)

    You don't need the Create method at all. Just use the constructor and one instance of the object:

    b myClassAb = new D1();
    Console.WriteLine(myClassAb.KM)

    C# csharp linq tutorial question lounge

  • Memory expensive rubber band selection?
    _ _Erik_

    Well, then, draw four rectangles around the area you want to keep clear. Just change the Paint event handler I posted before this way:

    private void pct_Paint(object sender, PaintEventArgs e)
    {
    if (drawRect)
    {
    e.Graphics.FillRectangle(br, 0, 0, pct.Width, r.Y);
    e.Graphics.FillRectangle(br, 0, r.Y, r.X, pct.Height);
    e.Graphics.FillRectangle(br, r.X, r.Y + r.Height, pct.Width, pct.Height);
    e.Graphics.FillRectangle(br, r.X + r.Width, r.Y, pct.Width, r.Height);
    }
    }

    This will work pretty well. Do you also want to save the image after you have darkened the area?

    C# graphics question performance

  • code for browser
    _ _Erik_

    No doubt, a question like this deserves to be here in the hall of shame.

    The Weird and The Wonderful com

  • Clicking a button with SendMessage [modified]
    _ _Erik_

    Have you tried SendInput[^] function?

    C# csharp testing question winforms beta-testing

  • abstarct class basic question [modified]
    _ _Erik_

    I am sorry but, what is the point in creating an instance of a class to just create another instance of the same class? I mean, since Create method is not static it would just work as a constructor so, why don't you just use a constructor? For example, what you want to do is this:

    D1 obj = new D1();
    D1 obj2 = D1.Create();

    And what I am saying is... why not?

    D1 obj = new D1();
    D1 obj2 = new D1();

    I guess you want a static Create method in your base class, don't you? In this case you will have to make your Create method static and use generics:

    abstract class BaseClass
    {
    public static T Create<T>() where T : BaseClass, new()
    {
    return new T();
    }
    }

    class DerivedClass : BaseClass { }

    This way you could use it like this:

    DerivedClass obj = BaseClass.Create<DerivedClass>();

    C# csharp linq tutorial question lounge

  • Memory expensive rubber band selection?
    _ _Erik_

    What I understand is that you are trying to darken a rectangle within a image, and that rectangle must be refreshed as long as the mouse is moving. Am I right? If this is what you want to do, the problem is that you are creating too many new Graphics and Bitmap objects in a very short time (and these are expensive objects), and updating the Image property a lot of times as well. The best way to do it is to subscribe to the Paint event of the control and code everything in this event handler, so you will receive a Graphics object as a parameter. In the next example there is only a PictureBox in the Form, called pct:

    public partial class Form1 : Form
    {
    bool drawRect = false;
    Rectangle r = new Rectangle();
    Brush br = new SolidBrush(Color.FromArgb(50, Color.Red));

    public Form1()
    {
        InitializeComponent();
    }
    
    private void pct\_Paint(object sender, PaintEventArgs e)
    {
        if (drawRect)
            e.Graphics.FillRectangle(br, r);
    }
    
    private void pct\_MouseDown(object sender, MouseEventArgs e)
    {
        drawRect = true;
        r.X = e.X;
        r.Y = e.Y;
    }
    
    private void pct\_MouseMove(object sender, MouseEventArgs e)
    {
        r.Width = e.X - r.X;
        r.Height = e.Y - r.Y;
    
        Refresh();
    }
    
    private void pct\_MouseUp(object sender, MouseEventArgs e)
    {
        drawRect = false;
        Refresh();
    }
    

    }

    I've made it quick. You would have to modify it in order to draw the rectangle if the mouse moves to a lower X and/or lower Y coordinate.

    C# graphics question performance

  • send fax with C# 2010 [modified]
    _ _Erik_

    Thanks... but I guess that would be more useful to the op, and maybe he will not see your post becouse you have answered to me.

    C# csharp tutorial question

  • richTextBox problem 2
    _ _Erik_

    As Luc has already suggested: Do not assign alltxt to rtb.Text nor richTextBox1.Text; Actually, remove rtb variable, you don't need it; Use alltxt.IndexOf method instead of rtb.Find method to search for the text you want. The indexes will be the same. Use these indexes to make the changes on your rich text box control. The lines:

    RichTextBox rtb = new RichTextBox(); rtb = richTextBox1;

    are useless becouse RichTextBox is a reference type, so your local rtb variable and your richTextBox1 will both be pointing to the same object.

    C# question help

  • How to Reslove Error?
    _ _Erik_

    Maybe this[^] will help you... or even us.

    Visual Basic database help tutorial question

  • Best fit polynomial curve to non-continuous data points [Solved]
    _ _Erik_

    Ok, now I understand it better. Then maybe bezier curves would be a better choice.

    Algorithms question com algorithms data-structures help

  • Best fit polynomial curve to non-continuous data points [Solved]
    _ _Erik_

    Not sure if this will help but, have you tried a spline interpolation algorithm?

    Algorithms question com algorithms data-structures help

  • Logic
    _ _Erik_

    Come on, guys. Stop this mess, ok? I don't pretend to know the absolute truth about this but, man, you are wrong or, at least, you might be confusing beginners. The fact that, as you say, "both terms are evaluated no matter what the first expression evaluates to" with the & operator is the key, and it is not a trivial difference. See this example:

    string s = null;
    bool b1 = s != null && s.Length == 0;
    bool b2 = s != null & s.Length == 0;

    You see the operands here are boolean expressions. However, while b1 would be assigned false without any problem, a runtime NullReferenceException would be thrown when trying to assing the value to b2. This is a really important difference. Both operands are not the same and can never be considered as if they were the same. Under some circumstances they can return the same result, yes, but that does not mean that they are exactly the same or that you can use any of them when you use boolean expressions. Can we, please, go on with our lifes now?

    The Weird and The Wonderful com help question

  • Logic
    _ _Erik_

    Fabio V Silva wrote:

    what makes you think I don't know the difference between & and &&?!

    Oh, nothing at all but, you know, this is a public forum, and although there are many posts in this thread none of them was giving a good explanation about the differencies between those operators, becouse there are differencies, I know them, you know them and I know you know them, but a beginner might get confused after reading this thread. That's all.

    The Weird and The Wonderful com help question
  • Login

  • Don't have an account? Register

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