Bits & Bytes

Posts Tagged ‘windows’

Transferring Files Via Windows Remote Desktop Connection

  • Search for “Remote Desktop Connection” and click the icon to open the application.
    Search for "Remote Desktop Connection"
  • Next Click the “Show Options” icon to open the tabbed screen with various selectable options.
    Click the Show Options Icon
  • On the options page, click the “Local Resources” tab.
    Click the Local Resources Tab
  • Click the “More…” button to open the device selection dialog.
    Click the More... button
  • Select the local drives that you wish to access and click the “OK” button.
    Select the local drives and Click OK
  • Finally, connect to the remote computer and you should see that the local drives are available.
    Access the local drives remotely

Fixing an Empty Battery Indicator in Windows

empty_battery

Shortly after accidentally dumping water on my computer and letting it dry out, it developed an odd error where the battery always indicated that it was empty even when it was fully charged. I searched unsuccessfully for a fix before finding a simple one of my own. This worked on a Windows 8.1 machine, but a similar fix will probably work on any version of Windows.

  1. Start by opening up the Control Panel
    1. Slide the cursor into the upper-right corner and bring it down along the right edge to open the side menu
    2. In the side menu, left-click Settings to open the right-side Settings menu.
    3. In the Settings menu, left-click Control Panel to open the Control Panel window shown below.

    control_panel

  2. Open the Device Manager
    1. Left-click Hardware and Sound (see above) in the Control Panel to open it.
    2. Left-click Device Manager in the Hardware and Sound window (below) under Devices and Printers.

    HardwareAndSound

  3. Uninstall all of the drivers under Batteries
    1. In the Device Manager and under Batteries, right-click a driver to open the context menu, as show below and left-click Uninstall
      uninstall_first
    2. A dialog like the one below may pop up. Left-click the OK button to confirm the uninstall.
      confirm
    3. Repeat those steps for each driver.
      uninstall_second
    4. When you are finished, the category for Batteries will be gone.
      device_manager
  4. Right-click the main computer icon to open the context menu shown below, and left-click Scan for hardware changes, as show below. This will replace the drivers. However, you may need to restart the computer to reset the battery indicator.
    scan


Using WPF in a C# Console Application

In this blog post, I demonstrate how to create a C# console application that can open a Windows Presentation Foundation window so that we can draw WPF graphics in a console program. The methodology is important because it can be used to add Windows Presentation Foundation classes to any type of C# project.

  1. To start, you should have a default C# Console Application project open. If you do not know how to create a C# console application project, you can consult our prior blog post on that topic.
    OpenProject
  2. Once you have a console application project open, it should have a Program.cs file with the following code inside it:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication {
        class Program {
            static void Main(string[] args) {
            }
        }
    }
    

    As the namespace indicates, the project was created using the default project name ConsoleApplication.

  3. We need to change some of the code. Begin by replacing the lines
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    

    with the line

    using System.Windows;
    
  4. Directly after the line
    class Program {

    add this line

    [STAThread]
  5. Directly after the line
    static void Main(string[] args) {

    add the following lines of code:

    Window qWindow = new Window();
    qWindow.Title = "WPF in Console";
    qWindow.Width = 400;
    qWindow.Height = 300;
    qWindow.ShowDialog();
    

    The final program should look like this

    using System;
    using System.Windows;
    
    namespace ConsoleApplication {
        class Program {
            [STAThread]
            static void Main(string[] args) {
                Window qWindow = new Window();
                qWindow.Title = "WPF in Console";
                qWindow.Width = 400;
                qWindow.Height = 300;
                qWindow.ShowDialog();
            }
        }
    }
    
  6. That is all of the code. Next, we need to add the libraries that the program uses. To do this, right-click References in the Solution Explorer pane on the right of the screen, and left-click Add Reference… in the context menu that pops up.
  7. That will open the Reference Manager dialog shown below. Navigate to Assemblies->Framework by left-clicking them, and then left-click the check boxes next to PresentationCore, PresentationFramework, and WindowsBase. Finish by left-clicking the OK button.
    ReferenceManager
  8. Now the code and project are ready. To compile and execute the program, left-click DEBUG in the menubar and left-click Start Without Debugging in the submenu. When it finishes compiling, you should see this window:
    Output

Perhaps the most important line of code in this program is [STAThread]. Without this, you can not compile WPF code. STA stands for Single Threaded Apartment. It is a directive for COM. the Component Object Model. If that does not makes sense, feel free to ignore it.

The code inside the Main() function, creates a Window object, sets the text in the title bar, sets the size of the window to 400 by 300 pixels, and causes the window to be displayed with the call to ShowDialog().

 

© 2007–2024 XoaX.net LLC. All rights reserved.