前回に引き続き、Windows8 ストアーアプリで、ドライブの空き容量を一覧で表示するアプリ
を作ろうとしているのだけれど、問題は全然解決していません。
デバイスの一覧を表示するプログラムのサンプルが有ったので
これを基に、ハードディスクドライブ(HDD) の一覧を表示させることはできたのですが
これだと、あくまで、ハードとしての HDD の一覧なので、
必要としている、ドライブの空き容量の情報を得られませんでした。
とりあえず、今回作った、HDDの一覧を表示するプログラムを載せておきます。
ボタンをクリックすると、HDDの一覧が表示されます。
Disk drive information Windows8 Store App C#
MainPage.xaml
====================================
<Page
x:Class="Disk_drive_information.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Disk_drive_information"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid x:Name="ContentRoot" Background="Black" Margin="100,20,100,20">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Header -->
<StackPanel x:Name="Header" Grid.Row="0">
<StackPanel Orientation="Horizontal"/>
</StackPanel>
<!-- Content -->
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Grid.Row="1" ZoomMode="Disabled">
<StackPanel x:Name="ContentPanel">
<Button x:Name="EnumerateInterfacesButton" Content="Enumerate" Margin="50,20,10,0" Click="EnumerateDeviceInterfaces" RenderTransformOrigin="0.821,0.921" HorizontalAlignment="Left" />
<TextBlock Text="Output" Margin="0,25,0,20" />
<StackPanel x:Name="Output" HorizontalAlignment="Left">
<TextBlock x:Name="OutputText" />
<!-- Device Interfaces-->
<ListBox x:Name="DeviceInterfacesOutputList" IsEnabled="False" BorderThickness="0" />
</StackPanel>
</StackPanel>
</ScrollViewer>
</Grid>
</Page>
====================================
MainPage.xaml.cs
====================================
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;
using Windows.Devices.Enumeration;
// 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
namespace Disk_drive_information
{
/// <summary>
/// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
/// <summary>
/// このページがフレームに表示されるときに呼び出されます。
/// </summary>
/// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter
/// プロパティは、通常、ページを構成するために使用します。</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
async void EnumerateDeviceInterfaces(object sender, RoutedEventArgs eventArgs)
{
EnumerateInterfacesButton.IsEnabled = false;
DeviceInterfacesOutputList.Items.Clear();
try
{
var selector = "System.Devices.InterfaceClassGuid:=
{53f56307-b6bf-11d0-94f2-00a0c91efb8b}"
+ " AND
System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True";
var interfaces = await DeviceInformation.FindAllAsync(selector, null);
OutputText.Text = interfaces.Count + " device interface(s) found\n\n";
foreach (DeviceInformation deviceInterface in interfaces)
{
DisplayDeviceInterface(deviceInterface);
}
}
catch (ArgumentException)
{
OutputText.Text = "Not";
}
EnumerateInterfacesButton.IsEnabled = true;
}
async void DisplayDeviceInterface(DeviceInformation deviceInterface)
{
var id = "Id: " + deviceInterface.Id;
var name = "name: "+ deviceInterface.Name;
var isEnabled = "IsEnabled: " + deviceInterface.IsEnabled;
var item = id + "\n" + name + "\n" + isEnabled + "\n" ;
DeviceInterfacesOutputList.Items.Add(item);
}
}
}
====================================
2012年11月30日金曜日
2012年11月29日木曜日
Win8 ストアアプリのプログラミングでDriveInfo が使えない
Windows8 ストアーアプリで、ドライブの空き容量を一覧で表示するアプリ
(感じ的には explorer で、コンピュータ を一覧表示させた、写真のような感じ)
を作ろうと思ったのですが、なかなかうまくいきません。
Desktop アプリなら DriveInfo で、簡単に取れる、ドライブの空き容量などの情報が
Windows8 ストアーアプリでは、取得できません。
というか、 DriveInfo クラス自体がないみたいです。
ネットで調べているのですが、なかなか上手い情報が見つかりません。
ドライブの空き領域を取得する方法なんて、すぐ見つかりそうなものなのに・・・。
とりあえず、Desktop アプリ で、ドライブ情報を取得するプログラムを載せておきます。
フォーム上の、ボタンをクリックすとドライブ情報が表示されます。
Windows8 Desktop C#
Form に Button と Label を配置
Form1.cs
====================================
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Disk_Drive_Info
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
label1.Text = "";
foreach (DriveInfo Dd in allDrives)
{
label1.Text += "Drive " + Dd.Name;
if (Dd.IsReady == true)
{
long FreeP = Dd.TotalFreeSpace * 100 / Dd.TotalSize;
label1.Text += " : " + FreeP.ToString() + "% Free ";
label1.Text += Dd.TotalFreeSpace / 1000000000 + "GB / ";
label1.Text += Dd.TotalSize / 1000000000 + "GB " + "\n\r";
// label1.Text += " Volume label: " + Dd.VolumeLabel + "\n\r";
// label1.Text += " File system: " + Dd.DriveFormat + "\n\r";
// label1.Text += " DriveType: " + Dd.DriveType + "\n\r";
}
else
{
label1.Text += " : " + "\n\r";
}
}
}
}
}
====================================
(感じ的には explorer で、コンピュータ を一覧表示させた、写真のような感じ)
を作ろうと思ったのですが、なかなかうまくいきません。
Desktop アプリなら DriveInfo で、簡単に取れる、ドライブの空き容量などの情報が
Windows8 ストアーアプリでは、取得できません。
というか、 DriveInfo クラス自体がないみたいです。
ネットで調べているのですが、なかなか上手い情報が見つかりません。
ドライブの空き領域を取得する方法なんて、すぐ見つかりそうなものなのに・・・。
とりあえず、Desktop アプリ で、ドライブ情報を取得するプログラムを載せておきます。
フォーム上の、ボタンをクリックすとドライブ情報が表示されます。
Windows8 Desktop C#
Form に Button と Label を配置
Form1.cs
====================================
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Disk_Drive_Info
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
label1.Text = "";
foreach (DriveInfo Dd in allDrives)
{
label1.Text += "Drive " + Dd.Name;
if (Dd.IsReady == true)
{
long FreeP = Dd.TotalFreeSpace * 100 / Dd.TotalSize;
label1.Text += " : " + FreeP.ToString() + "% Free ";
label1.Text += Dd.TotalFreeSpace / 1000000000 + "GB / ";
label1.Text += Dd.TotalSize / 1000000000 + "GB " + "\n\r";
// label1.Text += " Volume label: " + Dd.VolumeLabel + "\n\r";
// label1.Text += " File system: " + Dd.DriveFormat + "\n\r";
// label1.Text += " DriveType: " + Dd.DriveType + "\n\r";
}
else
{
label1.Text += " : " + "\n\r";
}
}
}
}
}
====================================
ラベル:
C#,
Win8,
Win8アプリ,
WinDesktop,
プログラム
2012年11月13日火曜日
コピペのスナップガジェット
Win8 では、サイドバーガジェットが使えなくなってしまいました。
今まで コピペ のガジェットを常用していたので、不便でなりません。
そこで、代わりにスナップしておける コピペ のプログラムを作ってみました。

画像の右端の部分です。
Copy ボタンをクリックすると、テキストボックスに入力してある文字を、
クリップボードにコピーします。
あとは入力したいところで、貼り付け します。
Win8 アプリでは、時計が表示されないので、
日付と時刻が表示されるようにしてみました。
下の丸いボタンは、設定を開くボタンなのですが、
今のところ、設定変更できる項目はありません。
ですが、このボタン(Settings) - 電源 - シャットダウン とクリックすれば、
マウスの移動が最小限でシャットダウンできます。
これが意外と便利なのですが、前の投稿にも書いたように、
時々設定画面がうまく開かない問題があり、まだ解決していません。
しかし、、、常に表示させておくには、スナップの幅が広すぎます。。。(T_T)
2012年11月12日月曜日
Win8 で時計を表示させるプログラム
Win8アプリで時計を表示さるC#のプログラム
なんか、これも今までどおりではうまくいかない。
TextBlock を以下の名前で、3つ作成しておく
Day_Text
Week_Text
Time_Text
MainPage.xaml.cs
-------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Threading.Tasks;
// 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
namespace Clock
{
/// <summary>
/// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// タイマー設定
startTimer();
}
/// <summary>
/// タイマー開始
/// </summary>
private void startTimer()
{
var timer = new DispatcherTimer();
/// タイマーの更新間隔ミリ秒
timer.Interval = TimeSpan.FromMilliseconds(200);
timer.Tick += onTimer;
timer.Start();
}
private void onTimer(object sender, object e)
{
// 時刻を表示
var now = DateTime.Now;
// 英語表示
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
// 日付
string text1 = now.ToString("yy/MM/dd");
this.Day_Text.Text = text1;
// 曜日
string text2 = now.ToString("ddd", ci);
this.Week_Text.Text = text2;
// 時間
// string text3 = now.ToString("HH:mm:ss");
string text3 = now.ToString("hh:mm:ss tt", ci);
this.Time_Text.Text = text3;
}
}
}
なんか、これも今までどおりではうまくいかない。
TextBlock を以下の名前で、3つ作成しておく
Day_Text
Week_Text
Time_Text
MainPage.xaml.cs
-------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Threading.Tasks;
// 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
namespace Clock
{
/// <summary>
/// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// タイマー設定
startTimer();
}
/// <summary>
/// タイマー開始
/// </summary>
private void startTimer()
{
var timer = new DispatcherTimer();
/// タイマーの更新間隔ミリ秒
timer.Interval = TimeSpan.FromMilliseconds(200);
timer.Tick += onTimer;
timer.Start();
}
private void onTimer(object sender, object e)
{
// 時刻を表示
var now = DateTime.Now;
// 英語表示
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
// 日付
string text1 = now.ToString("yy/MM/dd");
this.Day_Text.Text = text1;
// 曜日
string text2 = now.ToString("ddd", ci);
this.Week_Text.Text = text2;
// 時間
// string text3 = now.ToString("HH:mm:ss");
string text3 = now.ToString("hh:mm:ss tt", ci);
this.Time_Text.Text = text3;
}
}
}
-----------------------------------------------------------------------------
2012年11月11日日曜日
クリップボードにコピー
クリップボードにテキストをコピーするプログラム C#
今まで(デスクトップアプリ)は
Clipboard.SetText("Hello World!");
で済んでいましたが
Windows8アプリでは、とおりませんでした。
としたうえで、
DataPackage dataPackage = new DataPackage();
dataPackage.RequestedOperation = DataPackageOperation.Copy;
dataPackage.SetText("Hello World!");
Clipboard.SetContent(dataPackage);
としないといけないようです。
今まで(デスクトップアプリ)は
Clipboard.SetText("Hello World!");
で済んでいましたが
Windows8アプリでは、とおりませんでした。
using Windows.ApplicationModel.DataTransfer;
としたうえで、
DataPackage dataPackage = new DataPackage();
dataPackage.RequestedOperation = DataPackageOperation.Copy;
dataPackage.SetText("Hello World!");
Clipboard.SetContent(dataPackage);
としないといけないようです。
Win8 で スナップ状態からチャームの設定を表示させるプログラムのテスト
Windows8 で スナップ状態からボタンをクリックすると
チャームの設定を表示させるプログラムのテスト
VS C# で、デバッグの時はちゃんと動くのに
スタート画面から起動すると、なぜか 時々 止まる。。。
何がいけないのだろう???
MainPage にボタンを一つ配置
MainPage.xaml.cs
--------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.ApplicationSettings;
using Windows.UI.ViewManagement;
// 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=234238 を参照してください
namespace Test1
{
/// <summary>
/// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
/// <summary>
/// このページがフレームに表示されるときに呼び出されます。
/// </summary>
/// <param name="e">このページにどのように到達したかを説明するイベント データ。Parameter
/// プロパティは、通常、ページを構成するために使用します。</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
{
if (ApplicationView.Value == ApplicationViewState.Snapped)
{
Windows.UI.ViewManagement.ApplicationView.TryUnsnap();
}
SettingsPane.Show();
}
}
}
}
-----------------------------------------------------------------------
登録:
投稿 (Atom)

