Click here to Skip to main content
15,887,283 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XAML code

C#
<Grid>
        <StackPanel Orientation="Horizontal" Background="LightBlue" Height="40" VerticalAlignment="Top" >
            <Label Margin="10,0,0,0" Height="23" Name="Label1">
                Current File:
            </Label>
            <Label Margin="5,0,0,0" Height="25" Name="FileNameLabel" Width="300" />
            <Button Margin="5,0,0,0" Height="23" Name="BrowseButton" Width="75" Click="BrowseButton_Click">
                Browse
            </Button>
        </StackPanel>
        <StackPanel >
            <Image Name="ImageViewer1" Height="400" Width="400" />
        </StackPanel>
    </Grid>

C# code
private void BrowseButton_Click(object sender, RoutedEventArgs e)
      {
          Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
          dlg.InitialDirectory = &quot;c:\\&quot;;
          dlg.Filter = &quot;Image files (*.jpg)|*.jpg|All Files (*.*)|*.*&quot;;
          dlg.RestoreDirectory = true;
          bool? result = dlg.ShowDialog();
          if (dlg.ShowDialog ==System.Windows.Forms.DialogResult.OK)//this lines shown error
          {
              string selectedFileName = dlg.FileName;
              FileNameLabel.Content = selectedFileName;
              BitmapImage bitmap = new BitmapImage();
              bitmap.BeginInit();
              bitmap.UriSource = new Uri(selectedFileName);
              bitmap.EndInit();
              ImageViewer1.Source = bitmap;
          }
      }

when build the solution shown this error 

operator'==' cannot be applied to operands of type 'methodgroup' and 'System.Windows.Forms.DialogResult'

please give me the solution
Posted

dlg.ShowDialog no such property exists.
if (result ==System.Windows.Forms.DialogResult.OK)
change condition like this

change the line to bool? result = dlg.ShowDialog() to bool result = dlg.ShowDialog()
 
Share this answer
 
v2
Comments
Member 11939306 25-Nov-15 5:32am    
hi
now also show this error
operator '=='cannot be applied to operands of type 'bool?' and system.windows.forms.dialogresult
Yes it will: ShowDialog is a method.
Change this:
C#
if (dlg.ShowDialog ==System.Windows.Forms.DialogResult.OK)

To this:
C#
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
 
Share this answer
 
Comments
Member 11939306 25-Nov-15 5:32am    
hi
now also show this error
operator '=='cannot be applied to operands of type 'bool?' and system.windows.forms.dialogresult
OriginalGriff 25-Nov-15 5:48am    
Show Dialog does not return a bool or a nullable bool - it returns a System.Windows.Forms.DialogResult enumeration value.
Take that like out - you don't want to display the dialog twice anyway!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900