4

Error 1 The base class or interface 'System.ComponentModel.Component' in assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' referenced by type 'System.Windows.Forms.Timer' could not be resolved

k:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll App2

参照を追加した後、このエラー メッセージが表示されましたsystem.windows.forms

4

3 に答える 3

4

あなたはWpfを使用しているので、簡単な作業例を作成しました。プロジェクト参照が次のようになっていることを確認してください。

ここに画像の説明を入力

メインウィンドウ

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Timer tmr = new Timer();
        public MainWindow()
        {
            InitializeComponent();
            tmr.Interval = 2000;
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Start();
        }

        void tmr_Tick(object sender, EventArgs e)
        {
            tmr.Stop();
            throw new NotImplementedException();
        }
    }
}

また、roken が述べたように、Wpf Dispatcher Timer を使用できれば簡単です。リンクの例を見ると、Windows フォーム タイマーを使用する必要はありません。この場合、これは WPF プログラムであるため、Dispatcher タイマーは正常に動作します。

あなたのリンクに基づいて変更された編集

public partial class MainWindow : Window
{
    System.Windows.Threading.DispatcherTimer tmrStart = new System.Windows.Threading.DispatcherTimer();
    System.Windows.Threading.DispatcherTimer tmrStop = new System.Windows.Threading.DispatcherTimer();
    public MainWindow()
    {
        InitializeComponent();
        tmrStart.Interval = TimeSpan.FromSeconds(2); //Delay before shown
        tmrStop.Interval = TimeSpan.FromSeconds(3);  //Delay after shown
        tmrStart.Tick += new EventHandler(tmr_Tick);
        tmrStop.Tick += new EventHandler(tmrStop_Tick);

    }

    void tmrStop_Tick(object sender, EventArgs e)
    {
        tmrStop.Stop();
        label1.Content = "";
    }

    void tmr_Tick(object sender, EventArgs e)
    {
        tmrStart.Stop();
        label1.Content = "Success";
        tmrStop.Start();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        tmrStart.Start();
    }


}
于 2012-12-13T16:10:03.393 に答える
3

WPF のみを使用している場合は、System.Windows.Forms (WinForms) を参照する必要はありません。これらは 2 つの異なるテクノロジであり、必要でない限り、それらを混在させることはお勧めしません。

WinForms タイマーを使用している場合は、代わりにWPF のDispatcherTimerを使用することを検討してください。

于 2012-12-13T16:20:49.070 に答える
0

Systemへの参照を手動で追加してみてください。

1) プロジェクトを右クリックします。をクリックしUnload Projectます。

2) アンロードしたプロジェクトを右クリックします。クリックEdit <YourProjectName>.csproj

3)ItemGroupすべての<Reference Include="AssemblyName">sを含む を見つけて<Reference Include="System" />、新しい行に追加します。

4) ファイルを保存し、プロジェクトを右クリックして、Reload Project

于 2012-12-13T15:57:30.287 に答える