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

David Ewen

@David Ewen
About
Posts
12
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • rel=nofollow on article biography links
    D David Ewen

    Has there been any consideration given to removing the rel=nofollow from a users biography on articles as a reward for giving to the community? This is even alluded to as strategy by Google at Use rel="nofollow" for specific links[^].

    Quote:

    If you want to recognize and reward trustworthy contributors, you could decide to automatically or manually remove the nofollow attribute on links posted by members or users who have consistently made high-quality contributions over time.

    I would expect this would be limited to certain conditions to prevent spamming, a couple of obvious ones to me would be:

    • Specific articles where views >=50k and rating >=4
    • All articles for a user where the user has a certain reputation say gold or platinum

    My personal preference if this were to go ahead would be specific articles over a certain threshold this ensures that the reward is given to articles that haven proven to be useful to the community at large. -David

    Site Bugs / Suggestions com question

  • How can i know what is the bitmap color size of each pixel ?
    D David Ewen

    There doesn't appear to be an easy way to do this from what I can tell. but looking at the PixelFormat Enumeration[^] it is only going to be 8 or 16 bits per pixel so a small switch statement should do the job. The bigger question is why do you need to know this? There is most likely a better way as I have never needed to know this information.

    C# question tutorial graphics

  • Can you gain administrator permission in .NET program?
    D David Ewen

    The synchronization app is exactly the kind of app that should be implemented as a windows service even without the UAC prompting issues. UAC has imposed some architecture changes, configuration files should be place in “Application Settings” directories or isolated storage which are accessible without elevation. Similarly plug-ins can be placed and loaded from those 2 locations. A self updating app could be achieved be installing a basic exe to program files and then loading the bulk of the app code into app settings so it can be replaced if needed or UAC elevation for this feature is completely understandable and the standard practice (Firefox, OpenOffice, etc) all prompt for elevation when updating.

    C# csharp c++ question

  • Replace assembly at runtime
    D David Ewen

    Short answer: No Shortish answer: If you get to it early enough (before any types (or types that reference the types) are instantiated that reference the dlls) you can overwrite them. Long answer: If you need more than the above gives you like being able to swap the types after they have been used you need to create a seperate AppDomain and load the dlls into that. If they get updated you can destroy the AppDomain and create a new one with the new dlls. It all depends on what you are trying to achieve.

    C# csharp question announcement

  • How can I access my Mainwindow-controls from a thread?
    D David Ewen

    As a follow up this is how it is done in WPF.

    public MainWindow()
    {
    InitializeComponent();

    Thread workerThread = new Thread(WorkerThread);
    workerThread.Start();
    

    }

    private void WorkerThread()
    {
    UpdateWindowText(this);
    }

    private void UpdateWindowText(Window window)
    {
    window.Dispatcher.Invoke((Action) (() => window.Title = "test"));
    }

    C# question workspace

  • How can I access my Mainwindow-controls from a thread?
    D David Ewen

    I would have expected a cross thread exception rather than the one you got but the correct way to update gui elements from another thread is the call Invoke on the control. This is for WinForms not WPF.

    public Form1()
    {
    InitializeComponent();

    Thread workerThread = new Thread(WorkerThread);
    workerThread.Start();
    

    }

    private void WorkerThread()
    {
    UpdateWindowText(this);
    }

    private void UpdateWindowText(Form1 form)
    {
    form.Invoke((Action) (() => form.Text = "test"));
    }

    C# question workspace

  • Datagridview
    D David Ewen

    This will create a new row when the current new row gets clicked. I could see how this may be annoying for users though but I will assume you have your reasons.

    public Form1()
    {
    InitializeComponent();

    dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1\_CellClick);
    

    }

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
    DataGridView dataGridView = sender as DataGridView;
    if(dataGridView.Rows[e.RowIndex].IsNewRow)
    {
    int newRowIndex = dataGridView.Rows.Add();
    dataGridView.CurrentCell = dataGridView.Rows[newRowIndex].Cells[e.ColumnIndex];
    }
    }

    C# database tutorial

  • Can you gain administrator permission in .NET program?
    D David Ewen

    It is my understanding that apps like anti-virus programs appear to have admin access from their client tools because they talk to a windows service which is running with elevated privileges. The service is installed when you install the app (which you do get a UAC prompt for) after that point the client tools use IPC to communicate with the privileged service. There may be (and most probably are) exceptions to this rule, I have not done much work in this area. So if your app really needs admin privileges (it probably shouldn’t) a workaround would be to install a windows service which performs the admin functions and communicate with that.

    C# csharp c++ question

  • Array Help [modified]
    D David Ewen

    Without Linq then using loops like in first reponse by Nuri Ismail is the best approach.

    C# javascript data-structures tools help question

  • Array Help [modified]
    D David Ewen

    Either method will work with any sized array... The first method iterates over each entry in the souce array and pulls out values that start with whatever we are looking for ie "R=" and puts them into a new array. The second method works like this: Create an array of integers that represent the indexes in the source array Enumerable.Range(0, argbintArray.Length) In groups of 4 select every seconds index .Where(i => i % 4 == 1) Select the items out of the source array at the identified indexes .Select(i => argbintArray[i]) Hopefully that makes sense. Try outputing the result of each step it might help clear up what is happening.

    C# javascript data-structures tools help question

  • Array Help [modified]
    D David Ewen

    If you are using C# 4 you can do it like this:

    //if you have an array of strings
    string[] argbArray = new string[] { "A=255", "R=255", "G=0", "B=0", "A=255", "R=0", "G=255", "B=0" };
    string[] rArray = argbArray.Where(s => s.StartsWith("R=")).ToArray();
    string[] gArray = argbArray.Where(s => s.StartsWith("G=")).ToArray();
    string[] bArray = argbArray.Where(s => s.StartsWith("B=")).ToArray();

    //if you have an array of ints where the order is A,R,B,G. This would also work in the string one if the order was the same
    int[] argbintArray = new int[] { 255, 255, 0, 0, 255, 0, 255, 0 };
    int[] rintArray = Enumerable.Range(0, argbintArray.Length).Where(i => i % 4 == 1).Select(i => argbintArray[i]).ToArray();
    int[] gintArray = Enumerable.Range(0, argbintArray.Length).Where(i => i % 4 == 2).Select(i => argbintArray[i]).ToArray();
    int[] bintArray = Enumerable.Range(0, argbintArray.Length).Where(i => i % 4 == 3).Select(i => argbintArray[i]).ToArray();

    C# javascript data-structures tools help question

  • Unit testing
    D David Ewen

    As defined that method can not be unit tested as it requires user input (to select the file). But as you want an example on how to test a method that doesn't return a value it can be refactored slightly as below. To test a method that returns void you test for the change in system state that the method call is meant to impose. In this case the listbox should contain 2 items after the call, granted testing if items were added to a listbox is of dubious benefit but this is just for illustrative purposes.

    private void BtnLoad_Click(object sender, RoutedEventArgs e)
    {
    //Declare a new file dialog box
    OpenFileDialog dlg = new OpenFileDialog();

    //Set properties for the dialog...
    dlg.Title = "Select one or more media files";
    dlg.Multiselect = IsEnabled;
    dlg.Filter = "Media files(\*.mp3;\*.wav;\*.wma;\*.avi;\*.mp4;\*.mpg;\*.wmv)|\*.mp3;\*.wav;\*.wma;\*.avi;\*.mp4;\*.mpg;\*.wmv|All files(\*.\*)|\*.\*";
    
    //The result of the open file dialog is either true or false (didn't work).
    Nullable<bool> result = dlg.ShowDialog();
    
    //If the result of the open file dialog was true then....
    if (result == true)
    {
    	LoadFilesToListbox(dlg.FileNames);
    }
    

    }

    public void LoadFilesToListbox(string[] files)
    {
    //Add each file into the list box
    foreach (string file in files)
    {
    lstBxList.Items.Add(file);
    }
    }

    [TestMethod]
    public void TestLoadFilesToListbox()
    {
    LoadFilesToListbox(new string[] { "file1.txt", file2.dat" });
    Assert.AreEqual(2, lstBxList.Items.Count);
    }

    C# tutorial question csharp visual-studio com
  • Login

  • Don't have an account? Register

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