DOBON.NETプログラミング道掲示板
(現在 過去ログ3 を表示中)

[ 最新記事及び返信フォームをトピックトップへ ]

■34332 / inTopicNo.1)  PictureBox.Locationのキャンセル
  
□投稿者/ VBはじめました 一般人(7回)-(2019/10/28(Mon) 10:54:25)
  • アイコン環境/言語:[VB.NET] 
    分類:[.NET] 

    ウィンドウフォームにPictureBoxとButtomを配置して次のコードを実行すると、
    PictureBoxのイメージロードのキャンセルがキャッチできません。

    ところが、ボタンをもう一つ配置して、ロードが終わる前に、CancelAsyncを実行する(早業で・・・)すると、キャンセルできます。

    どのようなコードを書けば、キャンセルすることが可能になるのでしょうか?

    どなたか、詳しい方いらっしゃいましたら、教えて頂けないでしょうか?
    宜しくお願いいたします。

    Windows7 VisualStudio2017 VB.NET


    Imports System.ComponentModel
    Public Class Form3
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.PictureBox1.ImageLocation = "http://kemilia.ninja-web.net/free/yama1-1024.jpg"
    Me.PictureBox1.CancelAsync()
    End Sub
    Private Sub PictureBox1_LoadCompleted(sender As Object,
        e As AsyncCompletedEventArgs) Handles PictureBox1.LoadCompleted
    If e.Error IsNot Nothing Then
    MsgBox("読み込み時にエラーが発生しました。")
    ElseIf e.Cancelled Then
    MsgBox("キャンセルボタンが押されました。")
    Else
    MsgBox("読み込みが終わりました。")
    End If
    End Sub
    End Class
引用返信 削除キー/
■34333 / inTopicNo.2)  Re[1]: PictureBox.Locationのキャンセル
□投稿者/ Hongliang 大御所(568回)-(2019/10/28(Mon) 11:16:31)
  • アイコンPictureBox.LoadCompletedイベントのドキュメント
    https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.picturebox.loadcompleted?view=netframework-4.8
    には以下のように記述されています。

    > The LoadCompleted occurs only when the image is loaded asynchronously by using one of the LoadAsync methods, and WaitOnLoad is false.
    > If the image-load is canceled by calling the CancelAsync method the Cancelled property of the AsyncCompletedEventArgs will be set to true.

    (私訳)
    LoadCompletedイベントは、画像がLoadAsyncメソッドを使って非同期にロードされ、かつWaitOnLoadプロパティがfalseの時にだけ発生します。
    CancelAsyncメソッドの呼び出しによって画像ロードがキャンセルされた場合、AsyncCompletedEventArgsのCancelledプロパティがtrueに設定されます。

    // と言いつつ、LoadCompletedはLoadとかImageLocationとかでも発生しちゃってるようですが。
引用返信 削除キー/
■34334 / inTopicNo.3)  Re[2]: PictureBox.Locationのキャンセル
□投稿者/ VBはじめました 一般人(8回)-(2019/10/28(Mon) 14:40:00)
  • アイコンHongliangさん有難うございます。
    教えて頂いた通り、次のように変更するとできました。
    有難う御座いました。


    Private Sub Form3_Load(sender As Object, e As EventArgs) Handles Me.Load
    Me.PictureBox1.WaitOnLoad = False
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Me.PictureBox1.LoadAsync("http://kemilia.ninja-web.net/free/yama1-1024.jpg")
    Me.PictureBox1.CancelAsync()
    End Sub
    Private Sub PictureBox1_LoadCompleted(sender As Object, e As AsyncCompletedEventArgs) Handles PictureBox1.LoadCompleted
    If e.Error IsNot Nothing Then
    MsgBox("読み込み時にエラーが発生しました。")
    ElseIf e.Cancelled Then
    MsgBox("キャンセルボタンが押されました。")
    Else
    MsgBox("読み込みが終わりました。")
    End If
    End Sub
引用返信 削除キー/
■34335 / inTopicNo.4)  Re[3]: PictureBox.Locationのキャンセル
□投稿者/ VBはじめました 一般人(9回)-(2019/10/28(Mon) 14:40:46)
  • アイコンNo34334に返信(VBはじめましたさんの記事)

    解決済み押すの忘れました。
解決み!
引用返信 削除キー/



トピック内ページ移動 / << 0 >>

このトピックに書きこむ

過去ログには書き込み不可

Mode/  Pass/


- Child Tree -