Calculating windowing width and level from Image pixel data can be done via accessing the raw pixel data and applying your own algorithm or via the DicomObjects method SetDefaultWindows of the DicomImage object. The problem with this, however, is that there will be no correct values as the best values depend on which area of the image contains the anatomical region the user is interested in looking at (which is why viewer applications always have the tools to change them).

If you would like to try the DicomImage.SetDefaultWindows method, which does a simplistic calculation of the range of the data, and then sets the width to the range, and the level to the mid-point, but this will never be as good as a human can manage. In practice though people may find that using that method and then reducing the width a little (say to 80% of the calculated value) may at least give you a reasonable starting point for the user.