2014年1月22日のRobSherritの応答をインスピレーションとして使用して、新しいモジュールを作成し、次のコードを含むCKRFileDialog(必要なものと呼びます)と呼びました。
Public Function Show(fd As Object, CoveredForm As Form, Optional bShowHelp As Boolean = False) As DialogResult
Dim oDR As DialogResult
'The .Net FileDialogs open in the last Form that was created.
'To ensure they appear in the area of the current Form, we create a new HIDDEN PositionForm and then
'delete it afterwards.
Dim PositionForm As New Form With {
.StartPosition = FormStartPosition.Manual,
.Left = CoveredForm.Left + CInt(CoveredForm.Width / 8), 'adjust as required
.Top = CoveredForm.Top + CInt(CoveredForm.Height / 8), 'adjust as required
.Width = 0,
.Height = 0,
.FormBorderStyle = Windows.Forms.FormBorderStyle.None,
.Visible = False
}
PositionForm.Show()
'If you use SkyDrive you need to ensure that "bShowHelp" is set to True in the passed parameters.
'This is a workaround for a problem on W8.1 machines with SkyDrive installed.
'Setting it to "true" causes the "old" W7 control to be used which avoids a pointing to SkyDrive error.
'If you do not use SkyDrive then simply do not pass the last parameter (defaults to "False")
fd.ShowHelp = bShowHelp
'store whether the form calling this routine is set as "topmost"
Dim oldTopMost As Integer = CoveredForm.TopMost
'set the calling form's topmost setting to "False" (else the dialogue will be "buried"
CoveredForm.TopMost = False
oDR = fd.ShowDialog(PositionForm)
'set the "topmost" setting of the calling form back to what it was.
CoveredForm.TopMost = oldTopMost
PositionForm.Close()
PositionForm.Dispose()
Return oDR
End Function
次に、さまざまなモジュールでこのコードを次のように呼び出します。
「FileOpen」を実行する場合は、フォームまたはコードにFileOpenDialogコンポーネントが追加されていることを確認し、必要に応じてコンポーネントのプロパティを調整します(InitDirectory、Multiselectなど)。
FileSaveDialogコンポーネントを使用する場合も同じようにします(FileOpenDialogコンポーネントとは異なるプロパティが適用される場合があります)。
ダイアログコンポーネントを「表示」するには、次のコード行を使用して、2つのパラメーターを渡します。最初のパラメーターは使用しているFileDialog(「開く」または「保存」)で、2番目のパラメーターはダイアログをオーバーレイするフォームです。
CKRFileDialog.Show(saveFileDialog1、CoveredForm)またはCKRFileDialog.Show(openFileDialog1、CoveredForm)
SkyDriveを使用している場合は、3番目のパラメーターとして「True」を渡す必要があることに注意してください。
CKRFileDialog.Show(saveFileDialog1、CoveredForm、True)またはCKRFileDialog.Show(openFileDialog1、CoveredForm、True)
ダイアログの「オフセット」をフォーム「CoveredForm」の上下に1/8に設定しましたが、1/2(Rob Sherretのコードのように)または任意の値に戻すことができます。
これは最も簡単なアプローチのようでした
ありがとうロブ!:-)