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
E

Eslam Afifi

@Eslam Afifi
About
Posts
297
Topics
2
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • close form from its usercontrol
    E Eslam Afifi

    Yeah, Luc Pattyn's reply[^] reminded me of it. Of course a direct reference to the Form is better, that's what I said in my reply, I just forgot that the reference is already there as the TopLevelControl property provided by the framework.

    Eslam Afifi

    Windows Forms question csharp winforms com

  • close form from its usercontrol
    E Eslam Afifi

    One small issue with this is that the parent might not be the Form, it might be, for example, a Panel that might also be a hosted in another Panel. So if this scenario is possible (now or later in the future), the OP should either keep looking for the Form as in the code below or just give the UserControl a reference to the Form during initialization or something so it closes it directly, which is better (constant time instead of linear time).

    var parent = this.Parent;
    while (!(parent is Form))
    parent = parent.Parent;
    parent.Close();

    Eslam Afifi

    Windows Forms question csharp winforms com

  • Xml validation in c#
    E Eslam Afifi

    You're setting the ValidationType in the class level (outside a method).

    Eslam Afifi

    C# xml help csharp database

  • When and what do I Dispose when using GDI+
    E Eslam Afifi

    You're welcome.

    Eslam Afifi

    Visual Basic graphics winforms json help question

  • Deferred execution and eager evaluation
    E Eslam Afifi

    You're welcome.

    Eslam Afifi

    LINQ csharp linq help tutorial question

  • When and what do I Dispose when using GDI+
    E Eslam Afifi

    You should dispose objects that are IDisposable[^] because those objects' classes do implement this interface to provide the method Dispose to release unmanaged resources. In your code you should dispose the Bitmap and the Graphics objects. You should also read about the Using statement[^].

    Eslam Afifi

    Visual Basic graphics winforms json help question

  • XMLDocument for all MDI children
    E Eslam Afifi

    Yes.

    Eslam Afifi

    C# docker question

  • run save_changes for open children
    E Eslam Afifi

    Well, you can loop over the MdiChildren collection and call that save_changes method on each one.

    Eslam Afifi

    C# question

  • reduce image size
    E Eslam Afifi

    To resize an image,

    var originalImage = Bitmap.FromFile(imagePath);
    var resizedImage = new Bitmap(originalImage, newWidth, newHeight);

    I don't know about your requirements but I suggest you look into using a database but if you need to use an xml file may I suggest you save the images to disk and store the paths (relative paths) in the xml file since you'd be storing about 59 KB inside the xml file for each image which may increase the time required to parse the xml file and may make the xml file hit the size limit of the file system if you're storing a lot of images. Again, it's all about the requirements and what would be needed to be implemented in the future of the application.

    Eslam Afifi

    C# graphics xml performance

  • Deferred execution and eager evaluation
    E Eslam Afifi

    mbabube wrote:

    how we can implement eager evalation for deferred execution or how you example for the exger evaluation employs Deferred execution

    Eslam Afifi wrote:

    var elementsGreaterThan5Eager = (from n in arr where n > 5
    select n).ToArray();

    The query is deferred, using the ToArray method forces the execution of the query making it eager evaluation (at this point of the program you're looping over all the elements selecting those which match the criteria and putting them in an array). The eager evaluation of ToArray employs (uses) the deferred execution of the query. About the difference between deferred execution and lazy evaluation, the way I see it is that lazy evaluation gives you all the result value when you need it while deferred execution is executing only the part you need from an expression/query (not necessarily all of it) to evaluate another expression/query. I hope I understood your question right and that I gave you a good answer. And sorry for the late reply.

    Eslam Afifi

    LINQ csharp linq help tutorial question

  • associate file extension
    E Eslam Afifi

    http://www.codeproject.com/info/search.aspx?artkw=file+association[^]

    Eslam Afifi

    C# question

  • create a My Document Sub Directory
    E Eslam Afifi

    To create the directory, get the My Documents path using Environment.GetFolderPath then create the directory. Like this,

    Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Test Directory"));

    The appearance of the folder is determined by the desktop.ini[^] file.

    Eslam Afifi

    C# question

  • Deferred execution and eager evaluation
    E Eslam Afifi

    Lazy evaluation[^]: the value of an expression is not evaluated until it is needed. Eager evaluation[^]: the value of an expression is evaluated as soon as it gets bound to a variable.

    var arr = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

    var elementsGreaterThan5Lazy = from n in arr
    where n > 5
    select n; // the query doesn't execute here. If you have a million elements in the array you're not filtering them at this point of the program.

    var elementsGreaterThan5Eager = (from n in arr
    where n > 5
    select n).ToArray(); // the query does execute here because you're forcing the execution by creating an array of the results (you want those values > 5 now in an array).

    The first expression actually evaluates to an iterator (an object that is to perform the desired operation) not the actual result of the operation (the elements which are greater than 5). In the second expression, the ToArray method is forcing the execution of the query to get the elements as an array. In other words, you want an actual array now so the query has to be executed to get the array. Let's say you then write something like

    var firstElementGreaterThan5 = elementsGreaterThan5Lazy.First();

    Here you're forcing the query to execute to get the first element that is greater than 5 (and to throw an exception when the sequence is empty). Actually, you're not looping over all the elements, you're just looping until you find the desired value. In other words, if you have a million elements in the array and the first element greater than 5 is in the second location, you're actually doing 2 iterations and not iterating over the whole million elements. Some extension methods like ToArray, ToList, First, Last... do force the execution of the query. While other methods like Where, Take, Skip... do not execute the query but return an iterator. You can tell whether a method forces the execution or not from its name or from the documentation. I hope that answers your question.

    Eslam Afifi

    LINQ csharp linq help tutorial question

  • Check clipboard for a URL
    E Eslam Afifi

    Get the text from the Clipboard using the GetText method then match it against a URL regular expression.

    Eslam Afifi

    C# question

  • Group By
    E Eslam Afifi

    I assumed you were talking about LINQ-to-Objects so I didn't put a database into consideration while answering your question. I'm not aware of the BLOBing methods that you mentioned. Would you please provide a link to those methods? Are those points stored in a table or are they calculated per query? Is it possible to just store references to connected points (blobs) in another table and update it upon creation/deletion/modification of the points? Are the points' range so large that you can't represent them in a 2D array to perform scanline fill? I think you should say more about the nature of the data (the range of point's, how many blobs expected, how many points per blob, how many points are expected to be returned from a query...). I've read Gideon Engelberth[^] answer and it's checking for 8-connectivity. But you may need another pass over the groups to merge them, but that would be computationally expensive since you'll be determining whether 2 groups are connected or not by comparing the edges of the groups together (which requires calculating the edges of the groups during or after the first pass).

    Eslam Afifi

    LINQ question

  • Group By
    E Eslam Afifi

    So, you have a 2D array? If so, you can use Flood fill[^], Scanline fill[^] (which is actually an improved flood fill) or Connected Component Labeling[^]. If it's a collection of points, create a 2D array representation of the points and apply one of those algorithms. Or you may be able apply one of those logics to the collection. Whichever suits your needs.

    Eslam Afifi

    LINQ question

  • ListView issues
    E Eslam Afifi

    Nice. I'm looking forward to seeing it.

    Eslam Afifi

    WPF csharp question wpf winforms hardware

  • ListView issues
    E Eslam Afifi

    Yes, you are right. I'm aware of that, that's why I mentioned that the DisplayMemberBinding works when adding items to the Items manually. I tried both ways in a sample code before I first replied. This has just popped into my mind while I was reading your post, if it's not possible to make the List implement the INotifyCollectionChanged (If it's a class that inherits from List, which is what I understood from the question and the class is not to be touched. But I don't think implementing the interface would break existing code) then maybe creating a wrapper for (or inheriting from) the List (a custom List or just a List), implementing INotifyCollectionChanged and substituting the List with its wrapper (which would be implementing the interfaces of the original List) would be a better option. I haven't thought much about it and I'm interested to know what you think about it.

    Eslam Afifi

    WPF csharp question wpf winforms hardware

  • ListView issues
    E Eslam Afifi

    John Simmons / outlaw programmer wrote:

    the list cannot inherit from IBindingList or ObservableCollection

    I didn't say you should inherit from ObservableCollection. I said,

    Eslam Afifi wrote:

    bind to an ObservableCollection and add and remove items to that ObservableCollection manually

    Maybe I wasn't clear enough. In this case, I'm sorry. But I meant to bind to an ObservableCollection not the List in question. Something like that,

        List<A> \_aModels = new List<A>(); // the list not to be touched
        ObservableCollection<AViewModel> \_aViewModels = new ObservableCollection<AViewModel>();
    
        // and adding to to the ObservableCollection when adding to the List to keep them in sync. the same for removing.
        var aModel = new A { X = \_random.Next(), Y = \_random.Next(), Z = \_random.Next() };
        \_aModels.Add(aModel);
        \_aViewModels.Add(new AViewModel(aModel));
    
        // bind the ObservableCollection to the ListView's ItemsSource
    

    As for setting which property to use of columns. It works even when adding items manually to the ListView's Items property and not using ItemsSource. ItemsSource

    <ListView.View>
    <GridView>
    <GridView.Columns>
    <!-- the ViewModel exposes the X, Y and Z properties -->
    <GridViewColumn Header="X" DisplayMemberBinding="{Binding X}" Width="100" />
    <GridViewColumn Header="Y" DisplayMemberBinding="{Binding Y}" Width="100" />
    <GridViewColumn Header="Z" DisplayMemberBinding="{Binding Z}" Width="100" />
    </GridView.Columns>
    </GridView>
    </ListView.View>

    I replied to your question based on what I understood from it. You said you can't inherit from ObservableCollection and I don't think using a separate object of ObservableCollection would break the compatibility with the already existing windows forms code. If you mean you can't even use a separate instance of ObservableCollection because it breaks existing code, why would it break the code?

    Eslam Afifi

    WPF csharp question wpf winforms hardware

  • ListView issues
    E Eslam Afifi

    Why bind to the List itself when you can bind to an ObservableCollection and add and remove items to that ObservableCollection manually! and you should make that ObservableCollection of a ViewModel of the actual list items. I think that should work the way you want. About setting the property to use for the ListView columns, use the DisplayMemberBinding of the GridViewColumn. It works even when adding items manually to the ListView's Items property.

    Eslam Afifi

    WPF csharp question wpf winforms hardware
  • Login

  • Don't have an account? Register

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